Home >Backend Development >PHP Problem >How to view object methods in php

How to view object methods in php

藏色散人
藏色散人Original
2020-10-20 09:12:052904browse

phpView object methods: First create a PHP sample file; then define a class; finally print out all method names in the object through the "var_dump(get_class_methods($a));" method.

How to view object methods in php

Recommended: "PHP Video Tutorial"

PHP View all method names in the object

There are many methods in a class. Sometimes you are not sure which method to use for processing. You can print them all out and it will be clear at a glance what methods a class has.

<?php
class a
{
    public $a = 1;
    public function __construct() { }
    public function aaa()
    {
        echo "a";
    }
    public function get_name() { }
}
$a = new a();
var_dump( get_class_methods( $a ) );

Print results:

0 => string &#39;__construct&#39; (length=11)
1 => string &#39;aaa&#39; (length=3)
2 => string &#39;get_name&#39; (length=8)

The above is the detailed content of How to view object methods 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