Home  >  Article  >  Backend Development  >  php 魔术方法 debugInfo()

php 魔术方法 debugInfo()

WBOY
WBOYOriginal
2016-06-20 12:46:261210browse

array __debugInfo ( void )

该方法在var_dump()类对象的时候被调用,如果没有定义该方法,则var_dump会打印出所有的类属性

示例:

class C {    private $prop;    public function __construct($val) {        $this->prop = $val;    }    public function __debugInfo() {        return [            'propSquared' => $this->prop ** 2,        ];    }} var_dump(new C(42));

结果 :

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

 

 

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