php 魔术方法 debugInfo()

WBOY
Release: 2016-06-20 12:46:26
Original
1213 people have browsed it

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

结果 :

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

 

 

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