Bug #69264 [Com]: __debugInfo() ignored while extending SPL datastructures

From: Date: Wed, 17 Feb 2016 18:09:41 +0000
Subject: Bug #69264 [Com]: __debugInfo() ignored while extending SPL datastructures
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199306@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69264&edit=1

 ID:                 69264
 Comment by:         kb dot minter at gmail dot com
 Reported by:        grzegorz129 at gmail dot com
 Summary:            __debugInfo() ignored while extending SPL
                     datastructures
 Status:             No Feedback
 Type:               Bug
 Package:            SPL related
 Operating System:   All
 PHP Version:        5.6.6
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2015-03-29 04:22:18] 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.

------------------------------------------------------------------------
[2015-03-20 07:56:26] 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-20 04:43:37] 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-19 20:31:50] 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) {
  }
}


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69264&edit=1


Thread (10 messages)

« previous php.bugs (#199306) next »