MantisBT - Xdebug
View Issue Details
0001296XdebugUsage problems (Wrong Results)public2016-04-26 12:222017-02-07 17:11
greew 
derick 
highmajorhave not tried
feedbackopen 
MacOS X El Capitan10.11.4 (15E65)
2.4.0 
 
OS X
7.0.0-7.0.4
0001296: Using $this in __debugInfo() causes issues
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.
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);'
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 ~
No tags attached.
Issue History
2016-04-26 12:22greewNew Issue
2016-05-29 09:13derickNote Added: 0003619
2016-05-29 09:13derickAssigned To => derick
2016-05-29 09:13derickStatusnew => acknowledged
2016-05-29 12:41greewNote Added: 0003620
2016-05-29 12:44greewNote Added: 0003621
2016-07-31 13:36derickCategoryUsage problems => Usage problems (Crashes)
2016-07-31 13:38derickCategoryUsage problems (Crashes) => Usage problems (Wrong Results)
2016-12-04 15:50derickNote Added: 0003908
2016-12-04 15:50derickStatusacknowledged => confirmed
2017-01-14 17:38derickSummaryUsing $this in __debugInfo() causes infinite recursion (see 0001166) => Using $this in __debugInfo() causes issues
2017-01-14 18:23derickNote Added: 0004185
2017-01-14 18:23derickStatusconfirmed => feedback
2017-02-07 17:11derickNote Added: 0004204

Notes
(0003619)
derick   
2016-05-29 09:13   
I am not sure how this creates "infinite recursion", but I can reproduce your
output. I will need to investigate this.
(0003620)
greew   
2016-05-29 12:41   
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 :)
(0003621)
greew   
2016-05-29 12:44   
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
(0003908)
derick   
2016-12-04 15:50   
I can reproduce this issue still with PHP 7.0.13 and Xdebug 2.5.0RC2-dev.
(0004185)
derick   
2017-01-14 18:23   
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 [ "count" => 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?
(0004204)
derick   
2017-02-07 17:11   
Ping?