How to view object methods in php

藏色散人
Release: 2023-03-06 18:28:01
Original
2815 people have browsed it

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

Print results:

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

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!

Related labels:
php
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!