A small problem with php reflection api

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.