__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 [ 'propSquared' => $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!