Detailed explanation of __debugInfo() magic method in PHP

藏色散人
Release: 2023-04-07 06:54:01
Original
4299 people have browsed it

__debugInfo(), print the required debugging information

Note:

This method is only available in PHP 5.6.0 and above It can be used. If you find that it is invalid or an error is reported, please check your version.

Look at the code:

<?php
class C {
    private $prop;
    public function __construct($val) {
        $this->prop = $val;
    }
    /**
     * @return array
     */
    public function __debugInfo() {
        return [
            &#39;propSquared&#39; => $this->prop ** 2,
        ];
    }
}
var_dump(new C(42));
Copy after login

Result:

object(C)#1 (1) { ["propSquared"]=> int(1764) }
Copy after login

Note again:

The `**` here is the power Meaning, it can only be used in PHP5.6.0 and above. For details, please check PHP Manual

The above is the detailed content of Detailed explanation of __debugInfo() magic method 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!