MantisBT - Xdebug
View Issue Details
0001581XdebugUsage problems (Wrong Results)public2018-10-17 02:332018-10-17 16:18
pablosoria8286 
derick 
normalmajoralways
resolvedno change required 
LinuxUbuntu18.04
2.6.1 
 
Ubuntu 18.04
7.2.10-7.2.14
0001581: Local variables/function variables not shown when OPcache is enabled
If 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).
Sample 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();
PHP 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
No tags attached.
log xdebug_remote.log (21,085) 2018-10-17 02:33
https://bugs.xdebug.org/file_download.php?file_id=439&type=bug
Issue History
2018-10-17 02:33pablosoria8286New Issue
2018-10-17 02:33pablosoria8286File Added: xdebug_remote.log
2018-10-17 16:18derickNote Added: 0004703
2018-10-17 16:18derickStatusnew => resolved
2018-10-17 16:18derickResolutionopen => no change required
2018-10-17 16:18derickAssigned To => derick

Notes
(0004703)
derick   
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