PHP get overridden methods from child class

后端 未结 2 762
不思量自难忘°
不思量自难忘° 2021-01-02 11:45

Given the following case:



        
2条回答
  •  天命终不由人
    2021-01-02 12:47

    You can use ReflectionClass to achieve this:

    $ref = new ReflectionClass('ChildClass');
    
    print_r($ref->getMethods());
    print_r($ref->getProperties());
    

    This will output:

    Array
    (
        [0] => ReflectionMethod Object
            (
                [name] => methodA
                [class] => ChildClass
            )
    
    )
    
    Array
    (
        [0] => ReflectionProperty Object
            (
                [name] => attrB
                [class] => ChildClass
            )
    
    )
    

    See the manual for more useful information on reflection: http://uk3.php.net/manual/en/class.reflectionclass.php

提交回复
热议问题