View Issue Details

IDProjectCategoryView StatusLast Update
0002053XdebugStep Debuggingpublic2022-10-14 14:52
ReporterLazyOne Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Product Version3.1.1 
Summary0002053: PhpStorm incorrectly requests "GLOBALS" key in $GLOBALS array
Description

Evaluate window reports "Cannot get property" for array elements for PHP 8.1. At the same time the same steps work just fine when PHP 8.0 is used.

A bit more details can be seen in this PhpStorm ticket: https://youtrack.jetbrains.com/issue/WI-64532

Steps To Reproduce
    <?php
    declare(strict_types=1);
    class MyObject
    {
        public function __construct(public $pub, protected $prot, private $priv)
        {
        }
    }
    /** @var MyObject[] $arr */
    $arr = [
        new MyObject(1, 'first', true),
        new MyObject(2, 'second', false),
        new MyObject(3, '3rd', false),
    ];
    echo $arr[0]->pub; // breakpoint here

Try to debug the above code in PhpStorm 2021.3.

Once stopped at the breakpoint, see the content of $arr variable in the variables -- it expands the whole array just fine. Now use Evaluate window to see the same variable -- it will report "Cannot get property" for array elements (when they get expanded).

The same works with PHP 8.0 in the same environment (the same Xdebug version etc).

Additional Information

Windows 10 Pro 21H1 (OS build 19043.1415)
Xdebug 3.1.1

PHP 8.0.13 NTS x64

E:\Projects\php>E:\Projects\php\php80\php -v
PHP 8.0.13 (cli) (built: Nov 16 2021 21:59:04) ( NTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
Zend Engine v4.0.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies
    with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans

PHP 8.1.0 NTS x64

E:\Projects\php>E:\Projects\php\php81\php -v
PHP 8.1.0 (cli) (built: Nov 23 2021 21:46:10) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.0, Copyright (c), by Zend Technologies
    with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans
TagsNo tags attached.
Operating SystemWindows 10
PHP Version8.1.0-8.1.4

Activities

derick

2022-01-10 11:24

administrator   ~0006193

I've had a look now, and this is not really a bug on the Xdebug side. PhpStorm uses the -c 1 to switch to the "Globals" context, and then accesses in this context, the GLOBALS key. The globals context in PHP 8.1 does no longer contain the GLOBALS key as per https://wiki.php.net/rfc/restrict_globals_usage#proposal:

In this case the only difference is that there will no longer be a recursive “GLOBALS” key, which currently needs to be filtered out from most uses of $GLOBALS.

What PhpStorm should have sent to Xdebug is:


property_get -i 25 -n $IDE_EVAL_CACHE['91e1eabf-c286-40f7-9879-cccbe73c27c0'][0] -d 0 -c 1 -p 0

Which works both in PHP 7.2 through PHP 8.1: https://github.com/xdebug/xdebug/pull/816

derick

2022-10-14 14:52

administrator   ~0006400

FWIW, this has been fixed in PhpStorm for a while now: https://blog.jetbrains.com/phpstorm/2022/05/phpstorm-2022-1-1-is-released/#Xdebug_Cannot_get_property_bugfix_WI-65974