I've heard of get_class_methods()
but is there a way in PHP to gather an array of all of the public methods from a particular class?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Yes you can, take a look at the reflection classes / methods.
http://php.net/manual/en/book.reflection.php and http://www.php.net/manual/en/reflectionclass.getmethods.php
As
get_class_methods()
is scope-sensitive, you can get all the public methods of a class just by calling the function from outside the class' scope:So, take this class:
var_dump(get_class_methods('Foo'));
will output the following:While a call from inside the scope of the class (
new Foo;
) would return:After getting all the methods with
get_class_methods($theClass)
you can loop through them with something like this:Have you try this way?