How do I get the type of constructor parameter via reflection?

后端 未结 3 1079
自闭症患者
自闭症患者 2020-12-10 01:31

I\'m using type hinting on my constructor parameter list like so:

public function __construct(FooRepository $repository)

Is there a way to

3条回答
  •  忘掉有多难
    2020-12-10 01:38

    Are you trying to get the hinted type, or the actual type? I can't see why you could want to get the hinted type, as you know it is 'FooRepository' or PHP would have raised an error.

    You can get the actual type via get_class and you can also find out if a object inherits from a given class with ReflectionClass::isSubclassOf.

提交回复
热议问题