Home  >  Article  >  Backend Development  >  Detailed explanation of __debugInfo() magic method in PHP

Detailed explanation of __debugInfo() magic method in PHP

藏色散人
藏色散人Original
2019-07-27 14:07:254329browse

__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));

Result:

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

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!

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