1

now I have this:

class UserProvider
{
    protected string $className = User::class;

    /**
     * @param User $entity
     */
    public function getData($entity): array
    {
        $data['name'] = $entity->getName();

        return $data;
    }
}

but I am looking for something like this:

class UserProvider
{
    protected string $className = User::class;

    /**
     * @param [UserProvider->className] $entity
     */
    public function getData($entity): array
    {
        $data['name'] = $entity->getName();

        return $data;
    }
}

any ideas?

3
  • 2
    Is there any reason why you don't define the type of the actual parameter - getData(string $entity): array? Commented Oct 28, 2023 at 7:29
  • This looks like it's about being able to use Generics (stitcher.io/blog/generics-in-php-1) Commented Oct 28, 2023 at 7:34
  • What are you trying to do? Only type references I know, are self and static. Commented Oct 28, 2023 at 22:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.