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

From: Date: Fri, 03 Apr 2020 09:19:57 +0000
Subject: Bug #69264 [PATCH]: __debugInfo() ignored while extending SPL datastructures
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226418@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
 Patch added by:     cmb@php.net
 Reported by:        grzegorz129 at gmail dot com
 Summary:            __debugInfo() ignored while extending SPL
                     datastructures
 Status:             Re-Opened
 Type:               Bug
 Package:            SPL related
 Operating System:   All
 PHP Version:        5.6.6
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2020-04-01 13:50:44] 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

------------------------------------------------------------------------
[2018-08-13 08:04:19] requinix@php.net

Related To: Bug #71321

------------------------------------------------------------------------
[2018-08-13 07:54:24] 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 ))

------------------------------------------------------------------------
[2016-02-17 18:09:39] 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)
  }
}

------------------------------------------------------------------------
[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.

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=69264


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


Thread (10 messages)

« previous php.bugs (#226418) next »