PHP __debugInfo()


Example

This method is called by var_dump() when dumping an object to get the properties that should be shown. If the method isn't defined on an object, then all public, protected and private properties will be shown. — PHP Manual

class DeepThought {
    public function __debugInfo() {
        return [42];
    }
}
5.6
var_dump(new DeepThought());

The above example will output:

class DeepThought#1 (0) {
}
5.6
var_dump(new DeepThought());

The above example will output:

class DeepThought#1 (1) {
  public ${0} =>
  int(42)
}