Home > Article > Backend Development > How to get all method names of an object in php
In PHP, you can use the get_class_methods() function to get all the method names of the object. This function can get all the method names of the specified class (object) and return the method names into an array. The syntax "get_class_methods ($obj)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use the get_class_methods() function to get all method names of the object.
The get_class_methods() function can obtain all the method names of the specified class (object) and form an array. If an error occurs, null is returned.
<?php class Website { public $name, $url, $title; // method 1 public function demo1() { return (true); } // method 2 function demo2() { return (true); } // method 3 function demo3() { return (true); } } //实例化对象 $student = new Website(); $methods = get_class_methods($student); var_dump($methods);
Extended knowledge: How to get the current class name and method name?
To get the current class name and method name, you can use the magic constants "__CLASS__", "__FUNCTION__" and "__METHOD__"
__CLASS__
: The current class name (including the scope or namespace of the class);
Since PHP 5, this constant returns the name when the class was defined (case-sensitive). In PHP 4 this value is always lowercase.
__FUNCTION__
: The name of the current function (or method);
##__METHOD__: Current method name (including class name);
PHP Video Tutorial"
The above is the detailed content of How to get all method names of an object in php. For more information, please follow other related articles on the PHP Chinese website!