MantisBT

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001581XdebugUsage problems (Wrong Results)public2018-10-17 02:332018-10-17 16:18
Reporterpablosoria8286 
Assigned Toderick 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionno change required 
PlatformLinuxOSUbuntuOS Version18.04
Product Version2.6.1 
Target VersionFixed in Version 
Summary0001581: Local variables/function variables not shown when OPcache is enabled
DescriptionIf you try to debug the code below with OPCache enabled and put a breakpoint in the local variables you will see that they are not displayed. If you deactivate OPCache everything works as expected. Important to notice that OPcache is correctly activated first than Xdebug and that if you want to test it through cli you have to activate OPcache (by default is off on cli).
Steps To ReproduceSample Code:
-----------------------------
function hello($name){
    $localVariable = 2;
    return "Hello" . $name . $localVariable;
}

echo hello("World");
-----------------------------

In fact the variable $localVariable doesn't even appear in the log file.
The same occurs whit this code with classes and the $localFoo:
-----------------------------
class Foo {
    public $member = 'Some value';

    public function methodFoo() {
        $localFoo = "local";
        return $localFoo;
    }
}

$newFoo = new Foo();
echo $newFoo->methodFoo();
Additional InformationPHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans
TagsNo tags attached.
Operating SystemUbuntu 18.04
PHP Version7.2.10-7.2.14
Attached Fileslog file icon xdebug_remote.log [^] (21,085 bytes) 2018-10-17 02:33

- Relationships

-  Notes
(0004703)
derick (administrator)
2018-10-17 16:18

Hi,

This is a feature of OPCache. It optimised PHP code by sometimes removing variables if they are not needed. If you look at the opcodes that are generated, you see the following for your first example:

function name:  hello
number of ops:  7
compiled vars:  !0 = $name
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   EXT_NOP                                                  
         1        RECV                                             !0      
   3     2        EXT_STMT                                                 
   4     3        EXT_STMT                                                 
         4        CONCAT                                           0000002:0000002      'Hello', !0
         5        FAST_CONCAT                                      0000002:0000001      0000002:0000002, '2'
         6      > RETURN                                                   0000002:0000001

branch: #  0; line:     2-    4; sop:     0; eop:     6; out0:  -2
path #1: 0, 
End of function hello


There is no sign of $localVariable, and the "2" is just used inline in opcode 5 (the FAST_CONCAT).

There is nothing I can do about this, and I would recommend you disable OPCache when debugging.

cheers,
Derick

- Issue History
Date Modified Username Field Change
2018-10-17 02:33 pablosoria8286 New Issue
2018-10-17 02:33 pablosoria8286 File Added: xdebug_remote.log
2018-10-17 16:18 derick Note Added: 0004703
2018-10-17 16:18 derick Status new => resolved
2018-10-17 16:18 derick Resolution open => no change required
2018-10-17 16:18 derick Assigned To => derick


Copyright © 2000 - 2018 MantisBT Team
Powered by Mantis Bugtracker