In the manual, the isSubClass method of ReflectionClass in the php reflection api receives a string type parameter. But why does the ReflectionClass object pass in? {Code ...} both outputs are booleantrue, and the required parameter is a string ,... in the manual, the isSubClass method of ReflectionClass in the php reflection api receives a string type parameter. But why does the ReflectionClass object pass 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 outputs are boolean true. The required parameter is a string, but it is also feasible to pass the object parameter. Why?
Reply content:
In the manual, the isSubClass method of ReflectionClass in the php reflection api receives a string type parameter. But why does the ReflectionClass object pass 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 outputs are boolean true. The required parameter is a string, but it is also feasible to pass the object parameter. Why?
In the source code of php, two types can be input. The first is string and the second is reflectionclass.
Github address: github
Clearly in the code, you can see the description in the comment
/* {{{ proto public bool ReflectionClass::isSubclassOf(string|ReflectionClass class) Returns whether this class is a subclass of another class */
In addition, the next switch statement also makes a judgment.
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 it is normal that the document is not very detailed, and many things need to be tested by yourself.
Probably the manual is not fully written.
Is_subclass_of is estimated to refer to this function. This Manual describes that objects can be passed.
This is even a number of php vulnerabilities (it is also an advantage, after all, Lingling live ).
We recommend that you upload parameters according to the manual, because these minor vulnerabilities will be fixed in subsequent versions.
Or you can go to the php Manual's English document, which is more authoritative than the Chinese document.