View Issue Details

IDProjectCategoryView StatusLast Update
0001296XdebugUncategorizedpublic2017-03-04 10:45
Reportergreew Assigned Toderick  
PriorityhighSeveritymajorReproducibilityhave not tried
Status resolvedResolutionno change required 
PlatformMacOSOS X El CapitanOS Version10.11.4 (15E65)
Product Version2.4.0 
Summary0001296: Using $this in __debugInfo() causes issues
Description

When debugging with Xdebug 2.4.0 on PHP 7.0.5, stepping into an object that has a defined debugInfo() method that refers to $this causes an uncaught LogicException; 'The object is in an invalid state as the parent constructor was not called'
When single-stepping, the moment the first expression in the constructor is stepped into, execution skips to the
debugInfo() method, where it dies upon encountering $this.

Steps To Reproduce

php -dxdebug.auto_trace=1 -dxdebug.collect_params=3 -r 'class Foo extends IteratorIterator{function __construct($items){if(is_array($items)){$items=new ArrayIterator($items);}}function __debugInfo(){return ["count"=>iterator_count($this)];}};$a=new Foo([1,2,3]);var_dump($a);'

Additional Information

13:17 $ php -dxdebug.auto_trace=1 -dxdebug.collect_params=3 -r 'class Foo extends IteratorIterator{function construct($items){if(is_array($items)){$items=new ArrayIterator($items);}}function __debugInfo(){return ["count"=>iterator_count($this)];}};$a=new Foo([1,2,3]);var_dump($a);'
PHP Warning: Uncaught LogicException: The object is in an invalid state as the parent constructor was not called in Command line code:1
Stack trace:
#0 [internal function]: IteratorIterator->rewind()
#1 Command line code(1): iterator_count(Object(Foo))
0000002 [internal function]: Foo->
debugInfo()
0000003 Command line code(1): var_dump(Object(Foo))
0000004 {main}
thrown in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
PHP 2. var_dump(class Foo { }) Command line code:1

Warning: Uncaught LogicException: The object is in an invalid state as the parent constructor was not called in Command line code:1
Stack trace:
#0 [internal function]: IteratorIterator->rewind()
#1 Command line code(1): iterator_count(Object(Foo))
0000002 [internal function]: Foo->__debugInfo()
0000003 Command line code(1): var_dump(Object(Foo))
0000004 {main}
thrown in Command line code on line 1

Call Stack:
0.0005 349104 1. {main}() Command line code:0
0.0013 349296 2. var_dump(class Foo { }) Command line code:1

PHP Fatal error: __debuginfo() must return an array in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
PHP 2. var_dump(class Foo { }) Command line code:1

Fatal error: __debuginfo() must return an array in Command line code on line 1

Call Stack:
0.0005 349104 1. {main}() Command line code:0
0.0013 349296 2. var_dump(class Foo { }) Command line code:1

?-255 ~

TagsNo tags attached.
Operating SystemOS X
PHP Version7.0.0-7.0.4

Activities

derick

2016-05-29 08:13

administrator   ~0003619

I am not sure how this creates "infinite recursion", but I can reproduce your
output. I will need to investigate this.

greew

2016-05-29 11:41

reporter   ~0003620

No, I thoughtlessly copied the title of the issue, that I also referenced in the title - but too late I remembered to change it.
Sorry about that :)

greew

2016-05-29 11:44

reporter   ~0003621

Just tried reproducing it again in PHP 7.0.6 and XDebug 2.5.0-dev - still an issue.

13:43 $ php -dxdebug.auto_trace=1 -dxdebug.collect_params=3 -r 'class Foo extends IteratorIterator{function construct($items){if(is_array($items)){$items=new ArrayIterator($items);}}function __debugInfo(){return ["count"=>iterator_count($this)];}};$a=new Foo([1,2,3]);var_dump($a);'
PHP Warning: Uncaught LogicException: The object is in an invalid state as the parent constructor was not called in Command line code:1
Stack trace:
#0 [internal function]: IteratorIterator->rewind()
#1 Command line code(1): iterator_count(Object(Foo))
0000002 [internal function]: Foo->
debugInfo()
0000003 Command line code(1): var_dump(Object(Foo))
0000004 {main}
thrown in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
PHP 2. var_dump(class Foo { }) Command line code:1

Warning: Uncaught LogicException: The object is in an invalid state as the parent constructor was not called in Command line code:1
Stack trace:
#0 [internal function]: IteratorIterator->rewind()
#1 Command line code(1): iterator_count(Object(Foo))
0000002 [internal function]: Foo->__debugInfo()
0000003 Command line code(1): var_dump(Object(Foo))
0000004 {main}
thrown in Command line code on line 1

Call Stack:
0.0010 350840 1. {main}() Command line code:0
0.0032 351032 2. var_dump(class Foo { }) Command line code:1

PHP Fatal error: __debuginfo() must return an array in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
PHP 2. var_dump(class Foo { }) Command line code:1

Fatal error: __debuginfo() must return an array in Command line code on line 1

Call Stack:
0.0010 350840 1. {main}() Command line code:0
0.0032 351032 2. var_dump(class Foo { }) Command line code:1

derick

2016-12-04 15:50

administrator   ~0003908

I can reproduce this issue still with PHP 7.0.13 and Xdebug 2.5.0RC2-dev.

derick

2017-01-14 18:23

administrator   ~0004185

I tried this again, this time without Xdebug loaded (see the -n), and the result is exactly the same:

derick@whisky:~/dev/php/derickr-xdebug $ cat tests/bug01296.phpt
--TEST--
Test for bug 0001296: Using $this in debugInfo() causes issues
--FILE--
<?php
class Foo extends IteratorIterator
{
function
construct( $items )
{
if ( is_array( $items ) )
{
$items = new ArrayIterator( $items );
}
}

function __debugInfo()
{
    return [ &quot;count&quot; => iterator_count( $this ) ];
}

}

$a = new Foo( [ 1, 2, 3] );
var_dump( $a );
[GIT: issue1296-debuginfo][PHP: 7.0.13-dev ]
derick@whisky:~/dev/php/derickr-xdebug $ php -n tests/bug01296.phpt
--TEST--
Test for bug 0001296: Using $this in __debugInfo() causes issues
--FILE--

Warning: Uncaught LogicException: The object is in an invalid state as the parent constructor was not called in /home/derick/dev/php/derickr-xdebug/tests/bug01296.phpt:17
Stack trace:
#0 [internal function]: IteratorIterator->rewind()
#1 /home/derick/dev/php/derickr-xdebug/tests/bug01296.phpt(17): iterator_count(Object(Foo))
0000002 [internal function]: Foo->__debugInfo()
0000003 /home/derick/dev/php/derickr-xdebug/tests/bug01296.phpt(22): var_dump(Object(Foo))
0000004 {main}
thrown in /home/derick/dev/php/derickr-xdebug/tests/bug01296.phpt on line 17

Fatal error: __debuginfo() must return an array in /home/derick/dev/php/derickr-xdebug/tests/bug01296.phpt on line 22

So I fail to see why this is an Xdebug issue. Can you clarify please?

derick

2017-02-07 17:11

administrator   ~0004204

Ping?

derick

2017-03-04 10:45

administrator   ~0004227

Closing this as no additional feedback was provided, and the behaviour was the same without Xdebug loaded.

Issue History

Date Modified Username Field Change
2016-04-26 11:22 greew New Issue
2016-05-29 08:13 derick Note Added: 0003619
2016-05-29 08:13 derick Assigned To => derick
2016-05-29 08:13 derick Status new => acknowledged
2016-05-29 11:41 greew Note Added: 0003620
2016-05-29 11:44 greew Note Added: 0003621
2016-07-31 12:36 derick Category Usage problems => Usage problems (Crashes)
2016-07-31 12:38 derick Category Usage problems (Crashes) => Usage problems (Wrong Results)
2016-12-04 15:50 derick Note Added: 0003908
2016-12-04 15:50 derick Status acknowledged => confirmed
2017-01-14 17:38 derick Summary Using $this in debugInfo() causes infinite recursion (see 0001166) => Using $this in debugInfo() causes issues
2017-01-14 18:23 derick Note Added: 0004185
2017-01-14 18:23 derick Status confirmed => feedback
2017-02-07 17:11 derick Note Added: 0004204
2017-03-04 10:45 derick Note Added: 0004227
2017-03-04 10:45 derick Status feedback => resolved
2017-03-04 10:45 derick Resolution open => no change required
2020-03-12 16:35 derick Category Usage problems (Wrong Results) => Variable Display
2020-03-12 16:38 derick Category Variable Display => Uncategorized