1.2.1468. __debugInfo() Usage¶
The magic method __debugInfo() provides a custom way to dump an object.
It has been introduced in PHP 5.6. In the previous versions of PHP, this method is ignored and won’t be called when debugging.
<?php
// PHP 5.6 or later
class foo {
private $bar = 1;
private $reallyHidden = 2;
function __debugInfo() {
return ['bar' => $this->bar,
'reallyHidden' => 'Secret'];
}
}
$f = new Foo();
var_dump($f);
/* Displays :
object(foo)#1 (2) {
[bar]=>
int(1)
[reallyHidden]=>
string(6) Secret
}
*/
?>
See also Magic methods.
1.2.1468.1. Connex PHP features¶
1.2.1468.1.1. Specs¶
Short name |
Php/debugInfoUsage |
Rulesets |
All, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55 |
Exakat since |
0.8.4 |
PHP Version |
With PHP 5.6 and more recent |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Examples |
|
Available in |