How to view class methods in php

王林
Release: 2023-03-04 21:12:02
Original
2525 people have browsed it

To view the methods of classes in php, we can use the get_class_methods() method. This function can return an array consisting of class method names, for example: [get_class_methods($my_object)].

How to view class methods in php

get_class_methods — Returns an array consisting of class method names.

(Recommended tutorial: php graphic tutorial)

Description

array get_class_methods ( mixed $class_name )
Copy after login

Returns an array consisting of the method names defined in the class specified by class_name. If an error occurs, NULL is returned.

Note: Starting from PHP 4.0.6, you can specify the object itself instead of class_name, such as

<?php
    $class_methods = get_class_methods($my_object); // see below the full example
?>
Copy after login

(Learning video recommendation: php video tutorial)

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";
}
Copy after login

Output:

myclass
myfunc1
myfunc2
Copy after login

The above is the detailed content of How to view class methods 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!