That’s all we can say right now.
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.
// 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']]);
}
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']]);
}