Method Flux::getItemType() has invalid return type Item
663 * @return Item Type or false.
664 * @access public
665 */
666 public static function getItemType($id1)667 {
668 $type = self::config("ItemTypes")->toArray();
669
Description
The typehint provided for the function is not a valid class type. This may happen because of a typo, or the class specified in typehint is not present in the current namespace. You can also face this issue on using native union types if your PHP version is < 8.0. Native union types are only available in PHP 8.0 and later.
Bad Practice
// invalid: User class used as return type doesn't exists
function getUser(): User
{
return new User('John');
}
class User
{
public function update(array $data) {}
}
// invalid: Parameter type contains typo
function updateUser(Usr $user, array $data): void
{
$user->update(['name' => $data['name']]);
}
Recommended
Make sure class used in return typehint exists:
class User
{
private string $name;
public function __construct(string $name)
{
$this->name = $name;
}
}
function getUser(): User
{
return new User('John');
}
Make sure there are no typos:
class User
{
public function update(array $data) {}
}
// invalid: Parameter type contains typo
function updateUser(User $user, array $data): void
{
$user->update(['name' => $data['name']]);
}