Home > Article > Backend Development > How to get the attribute name of an object in php
There are many solutions:
Disadvantages: Only public
//只显示public的 var_dump(get_object_vars($test));
processing can be displayed : Define a public method in the class, which can be called by the external object to display all properties (except static properties)
function showAllProperties2(){ var_dump(get_object_vars($this)); }
to get all attribute names
//显示static的 class ABC { public static $instance='hello'; } function get_all_static($className) { $r = new ReflectionClass($className); var_dump($r->getProperties()); } get_all_static("ABC");
PS:
PHP: Reflection API
Use of PHP’s reflection classes ReflectionClass and ReflectionMethod Example
The above is the detailed content of How to get the attribute name of an object in php. For more information, please follow other related articles on the PHP Chinese website!