search
HomeBackend DevelopmentPHP ProblemHow to query the methods in a class in php

In PHP, you can use the get_class_methods() function to query what methods are in a class. This function can get all the methods of the class and return an array composed of the method names of the class. The syntax is "get_class_methods(class name) ')".

How to query the methods in a class in php

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 query what methods are in the class.

The get_class_methods() function can get all the methods of the class and return an array composed of the method names of the class.

Syntax:

get_class_methods($class_name)
  • $class_name: Class name or object instance.

Return value: Returns an array consisting of the method names defined in the class specified by $class_name. If an error occurs, null is returned.

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<br>";
}

?>

Output result:

How to query the methods in a class in php

##Note:

Since PHP 5, this The function returns the method by its defined name (case-sensitive). In PHP 4 always returns lowercase.

Recommended learning: "

PHP Video Tutorial"

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools