|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2015-03-19 20:31 UTC] grzegorz129 at gmail dot com
 Description:
------------
Magic method __debugInfo() should be always called while object is printed using var_dump(). Unfortunately it behaves differently if any class in chain extends SPL datastructure - it's simply ignored.
Test script:
---------------
<?php
class foo extends SplStack {
    public function __debugInfo() { return ['foo']; }
}
class bar extends foo {
    public function __debugInfo() { return ['bar']; }
}
class bar2 extends SplObjectStorage {
    public function __debugInfo() { return ['bar2']; }
}
var_dump((new bar), (new bar2));
Expected result:
----------------
object(bar)#1 (1) {
  [0]=>
  string(3) "bar"
}
object(bar2)#2 (1) {
  [0]=>
  string(4) "bar2"
}
Actual result:
--------------
object(bar)#1 (2) {
  ["flags":"SplDoublyLinkedList":private]=>
  int(6)
  ["dllist":"SplDoublyLinkedList":private]=>
  array(0) {
  }
}
object(bar2)#2 (1) {
  ["storage":"SplObjectStorage":private]=>
  array(0) {
  }
}
PatchesPull Requests
Pull requests: 
 HistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 11:00:01 2025 UTC | 
Here's a simple case to illustrate the problem. I create a class 'Mylist' that inherits from SplDoublyLinkedList. Mylist has one more public property "type" (integer). When var_dump i want to match the value to a name (from an array). so : final class Mylist extends \SplDoublyLinkedList { /* @var int */ public $type = 0; public function __debugInfo():array { return ['type' => Y::getName($this->type), "dllist" => $this->dllist]; } } When using var_dump, the value for type should be a string returned by Y::getName and NOT the actual 'type' (integer) value. BUT you can put whatever you want in '__debugInfo' it is currently TOTALY IGNORED. (PHP 7.2.2 (cli) (built: Jan 31 2018 19:31:17) ( ZTS MSVC15 (Visual C++ 2017) x64 ))