Gets all the properties of the PHP class and all methods that can be passed through the reflection mechanism

Source: Internet
Author: User
Tags php class

123456789101112131415161718192021 <?phpclass Class1{    public $var1 = ‘var1‘;    public $var2 = ‘var2‘;    private $var3 = ‘var3‘;    public function method1(){}    public function method2(){}    private function method3(){}}print_r(get_class_methods(Class1));print_r(get_class_vars(Class1));//用反射类可以获得私有属性和私有方法$ref = new ReflectionClass(Class1);//Class1 可以为对象实例 $class = new Class();print_r($ref->getMethods());print_r($ref->getProperties());

Output

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 Array(    [0] => method1    [1] => method2)Array(    [var1] => var1    [var2] => var2)Array(    [0] => ReflectionMethod Object        (            [name] => method1            [class] => Class1        )    [1] => ReflectionMethod Object        (            [name] => method2            [class] => Class1        )    [2] => ReflectionMethod Object        (            [name] => method3            [class] => Class1        ))Array(    [0] => ReflectionProperty Object        (            [name] => var1            [class] => Class1        )    [1] => ReflectionProperty Object        (            [name] => var2            [class] => Class1        )    [2] => ReflectionProperty Object        (            [name] => var3            [class] => Class1        ) )

Gets all the properties of the PHP class and all methods that can be passed through the reflection mechanism

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.