Home > Backend Development > PHP Problem > How to print out all methods of a class in php

How to print out all methods of a class in php

王林
Release: 2023-03-06 07:08:02
Original
3666 people have browsed it

php method to print out all methods of a class: You can use the get_class_methods() function to achieve this, which can return an array consisting of the method names of the class. If an error occurs, the function returns NULL.

How to print out all methods of a class in php

get_class_methods() function can return an array composed of class method names. If an error occurs, NULL is returned.

(Recommended tutorial: php video tutorial)

Grammar format:

get_class_methods ( mixed $class_name )
Copy after login

Example:

<?php

class myclass {
    // constructor
    function myclass()
    {
        return(true);
    }

    // method 1
    function myfunc1()
    {
        return(true);
    }

    // method 2
    function myfunc2()
    {
        return(true);
    }
}

$class_methods = get_class_methods(&#39;myclass&#39;);
// or
$class_methods = get_class_methods(new myclass());

foreach ($class_methods as $method_name) {
    echo "$method_name\n";
}

?>
Copy after login

Output results :

myclass
myfunc1
myfunc2
Copy after login

Related recommendations: php training

The above is the detailed content of How to print out all methods of a class in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template