The manual that writes the Reflectionclass Issubclass method in the PHP reflection API is a string type, but why is it possible to pass the Reflectionclass object in?
class test1 { public $a;}class test1 extends test{ public $b;}$object1 = new ReflectionClass('test1');$object2 = new ReflectionClass('test2');var_dump($object2 -> isSubclassOf($object2));var_dump($object2 -> isSubclassOf('test1'));
Both of these outputs are Boolean true, and the required arguments are strings, but it is also possible to pass the object parameters, which is why?
Reply content:
The manual that writes the Reflectionclass Issubclass method in the PHP reflection API is a string type, but why is it possible to pass the Reflectionclass object in?
class test1 { public $a;}class test1 extends test{ public $b;}$object1 = new ReflectionClass('test1');$object2 = new ReflectionClass('test2');var_dump($object2 -> isSubclassOf($object2));var_dump($object2 -> isSubclassOf('test1'));
Both of these outputs are Boolean true, and the required arguments are strings, but it is also possible to pass the object parameters, which is why?
Because in the source code of PHP here is the two types can be passed in, the first is the string second is Reflectionclass.
Address on GitHub: GitHub
It is clear in the code that you can see in the comments
/* {{{ proto public bool ReflectionClass::isSubclassOf(string|ReflectionClass class) Returns whether this class is a subclass of another class */
and is judged in the next switch statement.
switch (Z_TYPE_P(class_name)) { case IS_STRING: //some code case IS_OBJECT: //some code default: //some code }
PHP has a lot of external maintainers, so the document is not very detailed is also normal, a lot of things need to try their own.
Probably the manual didn't write it all.
IS_SUBCLASS_OF estimates refer to this function, which says that the object can be passed.
This is some of PHP's vulnerabilities (also considered an advantage, after all, the spirit of flexibility).
It is recommended to follow the manual upload parameters, because these small loopholes will be repaired in subsequent releases.
Or you can go to the English document of the PHP manual, which is more authoritative than the Chinese document