php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69264 __debugInfo() ignored while extending SPL datastructures
Submitted: 2015-03-19 20:31 UTC Modified: 2020-04-03 09:20 UTC
Votes:8
Avg. Score:4.0 ± 1.0
Reproduced:7 of 7 (100.0%)
Same Version:1 (14.3%)
Same OS:6 (85.7%)
From: grzegorz129 at gmail dot com Assigned: cmb (profile)
Status: Closed Package: SPL related
PHP Version: 5.6.6 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: grzegorz129 at gmail dot com
New email:
PHP Version: OS:

 

 [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) {
  }
}

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-20 04:43 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2015-03-20 04:43 UTC] laruence@php.net
not sure about this, but the current behavior also could be explained.  it is always exposed the intern state..  (maybe mark it as final could reslove the confused, but bc break)
 [2015-03-20 07:56 UTC] grzegorz129 at gmail dot com
It should NOT be marked as final I think.
I noticed that strange behaviour during actual usage of SplObjectStorage with really deep objects. Using __debugInfo() to print only object ids is a bless.
 [2015-03-29 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2016-02-17 18:09 UTC] kb dot minter at gmail dot com
This happens with ArrayObject as well. The problem is that internal classes that are extended do not allow for overriding outputting of the internal state.

Able to replicate the problem with each PHP version since this functionality has been added...

https://3v4l.org/ddq2i

For those not wanting to click on an external link...

Script:
----------------
<?php

class Base extends ArrayObject{
    var $parent = true;
    var $another_prop = 123;
    public function __construct() {
        $this['test'] = 123;
    }
    public function __debugInfo() {
        return [
            'parent'=>$this->getArrayCopy()
        ];
    }
}

class Child extends Base {
    var $parent = false;
}

var_dump(new Child());

Expected result:
----------------
object(Child)#1 (1) {
  ["parent"]=>
  array(1) {
    ["test"]=>
    int(123)
  }
}
Actual result:
----------------
object(Child)#1 (3) {
  ["parent"]=>
  bool(false)
  ["another_prop"]=>
  int(123)
  ["storage":"ArrayObject":private]=>
  array(1) {
    ["test"]=>
    int(123)
  }
}
 [2018-08-13 07:54 UTC] zerterone at gmail dot com
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 ))
 [2018-08-13 07:56 UTC] requinix@php.net
-Status: No Feedback +Status: Re-Opened
 [2020-04-01 13:50 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #69264: __debugInfo() ignored while extending SPL classes
On GitHub:  https://github.com/php/php-src/pull/5333
Patch:      https://github.com/php/php-src/pull/5333.patch
 [2020-04-03 09:19 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #69264: __debugInfo() ignored while extending SPL classes
On GitHub:  https://github.com/php/php-src/pull/5342
Patch:      https://github.com/php/php-src/pull/5342.patch
 [2020-04-03 09:20 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-04-06 10:05 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=22a077b642815a2e1c36ba03df906146c9ecbe50
Log: Fix #69264: __debugInfo() ignored while extending SPL classes
 [2020-04-06 10:05 UTC] cmb@php.net
-Status: Re-Opened +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 10:01:28 2024 UTC