Local variables not shown when OPcache is enabled while debugging with Xdebug

会有一股神秘感。 提交于 2019-12-24 09:13:16

问题


I have Xdebug enabled and working together with OPcache. OPcache module is loaded first by phpfpm (important). If you try to debug the code below (from the browser) and put a breakpoing in the local variables you will see that they are not displayed. If I deactivate OPCache everything works as expected. I'm using PhpStorm 2018.2.5 to debug.

class Foo {
    public $member = 'Some value';

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

class Bar {
    public $firstMember = "foo";
    public $secondMember = "bar";

    public function create() {
        $localBar = 10;
        $newFoo = new Foo();
        $newFoo->methodFoo();
        $localBar += 1;
        $this->firstMember = "Other value";
    }

}

$foo = "testing";
$bar = "testing2";

$obj = new Bar();
$obj->create();

I do not know if I miss something or it's a bug. Years ago there was a similar bug in xdebug but it was not related to OPcache: bug

I leave the information related to my system and the log of Xdebug

phpinfo()
PHP Version => 7.2.10-0ubuntu0.18.04.1

System => Linux pablo-dv6 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64
Build Date => Sep 13 2018 13:45:02
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php/7.2/cli
Loaded Configuration File => /etc/php/7.2/cli/php.ini
Scan this dir for additional .ini files => /etc/php/7.2/cli/conf.d
Additional .ini files parsed => /etc/php/7.2/cli/conf.d/10-opcache.ini,
/etc/php/7.2/cli/conf.d/10-pdo.ini,
/etc/php/7.2/cli/conf.d/15-xml.ini,
/etc/php/7.2/cli/conf.d/20-calendar.ini,
/etc/php/7.2/cli/conf.d/20-ctype.ini,
/etc/php/7.2/cli/conf.d/20-curl.ini,
/etc/php/7.2/cli/conf.d/20-dom.ini,
/etc/php/7.2/cli/conf.d/20-exif.ini,
/etc/php/7.2/cli/conf.d/20-fileinfo.ini,
/etc/php/7.2/cli/conf.d/20-ftp.ini,
/etc/php/7.2/cli/conf.d/20-gettext.ini,
/etc/php/7.2/cli/conf.d/20-iconv.ini,
/etc/php/7.2/cli/conf.d/20-intl.ini,
/etc/php/7.2/cli/conf.d/20-json.ini,
/etc/php/7.2/cli/conf.d/20-mbstring.ini,
/etc/php/7.2/cli/conf.d/20-pdo_sqlite.ini,
/etc/php/7.2/cli/conf.d/20-phar.ini,
/etc/php/7.2/cli/conf.d/20-posix.ini,
/etc/php/7.2/cli/conf.d/20-readline.ini,
/etc/php/7.2/cli/conf.d/20-shmop.ini,
/etc/php/7.2/cli/conf.d/20-simplexml.ini,
/etc/php/7.2/cli/conf.d/20-sockets.ini,
/etc/php/7.2/cli/conf.d/20-sqlite3.ini,
/etc/php/7.2/cli/conf.d/20-sysvmsg.ini,
/etc/php/7.2/cli/conf.d/20-sysvsem.ini,
/etc/php/7.2/cli/conf.d/20-sysvshm.ini,
/etc/php/7.2/cli/conf.d/20-tokenizer.ini,
/etc/php/7.2/cli/conf.d/20-wddx.ini,
/etc/php/7.2/cli/conf.d/20-xmlreader.ini,
/etc/php/7.2/cli/conf.d/20-xmlwriter.ini,
/etc/php/7.2/cli/conf.d/20-xsl.ini,
/etc/php/7.2/cli/conf.d/20-zip.ini,
/etc/php/7.2/cli/conf.d/30-xdebug.ini

PHP API => 20170718
PHP Extension => 20170718
Zend Extension => 320170718
Zend Extension Build => API320170718,NTS
PHP Extension Build => API20170718,NTS
Debug Build => no
Thread Safety => disabled
Zend Signal Handling => enabled
Zend Memory Manager => enabled
Zend Multibyte Support => provided by mbstring
IPv6 Support => enabled
DTrace Support => available, disabled

Registered PHP Streams => https, ftps, compress.zlib, php, file, glob, data, http, ftp, phar, zip
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filters => zlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, convert.iconv.*

This program makes use of the Zend Scripting Language Engine:
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


Zend OPcache

Opcode Caching => Disabled
Optimization => Disabled
SHM Cache => Enabled
File Cache => Disabled
Startup Failed => Opcode Caching is disabled for CLI

Directive => Local Value => Master Value
opcache.blacklist_filename => no value => no value
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => On => On
opcache.enable_cli => Off => Off
opcache.enable_file_override => Off => Off
opcache.error_log => no value => no value
opcache.file_cache => no value => no value
opcache.file_cache_consistency_checks => 1 => 1
opcache.file_cache_only => 0 => 0
opcache.file_update_protection => 2 => 2
opcache.force_restart_timeout => 180 => 180
opcache.huge_code_pages => Off => Off
opcache.inherited_hack => On => On
opcache.interned_strings_buffer => 8 => 8
opcache.lockfile_path => /tmp => /tmp
opcache.log_verbosity_level => 1 => 1
opcache.max_accelerated_files => 10000 => 10000
opcache.max_file_size => 0 => 0
opcache.max_wasted_percentage => 5 => 5
opcache.memory_consumption => 128 => 128
opcache.opt_debug_level => 0 => 0
opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF
opcache.preferred_memory_model => no value => no value
opcache.protect_memory => 0 => 0
opcache.restrict_api => no value => no value
opcache.revalidate_freq => 2 => 2
opcache.revalidate_path => Off => Off
opcache.save_comments => 1 => 1
opcache.use_cwd => On => On
opcache.validate_permission => Off => Off
opcache.validate_root => Off => Off
opcache.validate_timestamps => On => On

Xdebug log related to this part (you can see that $localBar doesn't appear):

<- context_get -i 46 -d 0 -c 0
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="46" context="0"><property name="$newFoo" fullname="$newFoo" type="uninitialized"></property><property name="$this" fullname="$this" type="object" classname="Bar" children="1" numchildren="2" page="0" pagesize="100"><property name="firstMember" fullname="$this-&gt;firstMember" facet="public" type="string" size="3" encoding="base64"><![CDATA[Zm9v]]></property><property name="secondMember" fullname="$this-&gt;secondMember" facet="public" type="string" size="3" encoding="base64"><![CDATA[YmFy]]></property></property></response>

Any help is welcome, thanks :)


回答1:


I answer myself, in case it serves to someone. This is a feature of OPCache. It optimizes PHP code by sometimes removing variables if they are not needed. Solution: disable OPCache when debugging.

sudo phpdismod opcache

And restart phpfpm or apache according to your environment

sudo service php7.2-fpm restart

or

sudo service apache2 restart

More info here.



来源:https://stackoverflow.com/questions/52842099/local-variables-not-shown-when-opcache-is-enabled-while-debugging-with-xdebug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!