我的配置:
- CakePHP 版本:3.6.13
- 平台和目标:PHP 7.2、MySQL 5.7、Ubuntu 16.04.5 LTS、Vagrant、Apache、php-fpm、PhpStorm 2019.1 EAP
php -v 输出
PHP 7.2.13-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Dec 7 2018 08:07:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.13-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans
xdebug 配置
/etc/php/7.2/cli/conf.d/99-xdebug.ini,
xdebug
xdebug support => enabled
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.coverage_enable => On => On
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.extended_info => On => On
xdebug.file_link_format => no value => no value
xdebug.filename_format => no value => no value
xdebug.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.gc_stats_enable => Off => Off
xdebug.gc_stats_output_dir => /tmp => /tmp
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => PHPSTORM => PHPSTORM
xdebug.max_nesting_level => 256 => 256
xdebug.max_stack_frames => -1 => -1
xdebug.overload_var_dump => 2 => 2
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => On => On
xdebug.profiler_enable_trigger_value => no value => no value
xdebug.profiler_output_dir => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_addr_header => no value => no value
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => 10.0.2.2 => 10.0.2.2
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.remote_timeout => 200 => 200
xdebug.scream => Off => Off
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_enable_trigger_value => no value => no value
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3
最初我在 GitHub 上发布了我认为是 cakephp 中的错误。
见https://github.com/cakephp/cakephp/issues/13020
总之,似乎foreach
没有迭代Traversable
包含数据库查询结果的对象。我通过首先将对象转换为数组并在调试器中检查对象显示有要迭代的项目来确认有结果要迭代。转换为数组后,foreach
按预期迭代元素。
当我禁用监听时xdebug
,将按预期foreach
迭代对象,而无需先转换为数组。Traversable
我已经尝试xdebug.collect_params=1
按照@Asgraf 在我的原始帖子中建议的设置,但这并没有解决任何问题。
当我尝试Traversable
在调试器中评估对象中的第一个元素时,在下面的 foreach 循环之前,执行立即退出。
$mapper = $this->_mapper;
foreach ($this->_data as $key => $val) {
$mapper($val, $key, $this);
}
下面是 ResultSet 的层次结构,如果它有助于提供一些清晰性的话。
任何有关正在发生的事情或如何解决这种奇怪行为的见解将不胜感激。
更新日志
PhpStorm 日志
2019-02-26 12:13:21,241 [ 967833] DEBUG - il.connection.ServerConnection - Incoming connection on port 9000 from 127.0.0.1
2019-02-26 12:13:21,247 [ 967839] DEBUG - .connection.PhpDebugConnection - 1709495916#----connection started
2019-02-26 12:13:21,332 [ 967924] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@294dfd25
2019-02-26 12:13:21,332 [ 967924] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@1d499b6f
2019-02-26 12:13:21,336 [ 967928] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpRemotePathMapper@25da7f64
2019-02-26 12:13:21,336 [ 967928] DEBUG - .php.run.filters.PhpUnitFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpRemotePathMapper@25da7f64
2019-02-26 12:13:21,336 [ 967928] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpRemotePathMapper@25da7f64
2019-02-26 12:13:21,482 [ 968074] DEBUG - p.debug.common.PhpDebugProcess - 1947777361# Stop at ('file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php':177)
2019-02-26 12:13:21,482 [ 968074] DEBUG - p.debug.common.PhpDebugProcess - 1947777361# remote: 'file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' <-> local: '/Users/myorkgitis/Documents/phpstorm-workspace/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php'
2019-02-26 12:13:21,483 [ 968075] DEBUG - p.debug.common.PhpDebugProcess - 1947777361# remote: 'file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' <-> extracted: '/var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php'
2019-02-26 12:13:21,509 [ 968101] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@2f1cc1ce
2019-02-26 12:13:21,510 [ 968102] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@484b8985
2019-02-26 12:13:30,780 [ 977372] DEBUG - p.debug.common.PhpDebugProcess - 1947777361# Stop at ('file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php':178)
2019-02-26 12:13:30,780 [ 977372] DEBUG - p.debug.common.PhpDebugProcess - 1947777361# remote: 'file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' <-> local: '/Users/myorkgitis/Documents/phpstorm-workspace/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php'
2019-02-26 12:13:30,780 [ 977372] DEBUG - p.debug.common.PhpDebugProcess - 1947777361# remote: 'file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' <-> extracted: '/var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php'
2019-02-26 12:13:37,262 [ 983854] DEBUG - .connection.PhpDebugConnection - 1709495916#---input stream is finished
2019-02-26 12:13:37,262 [ 983854] DEBUG - .connection.PhpDebugConnection - 1709495916#---stop reading
2019-02-26 12:13:37,262 [ 983854] DEBUG - .connection.PhpDebugConnection - 1709495916#---stop writing
2019-02-26 12:13:37,262 [ 983854] DEBUG - .connection.PhpDebugConnection - 1709495916#----connection stopped
2019-02-26 12:13:37,263 [ 983855] DEBUG - il.connection.ServerConnection - ----socket closed
调试日志
xdebug 日志没有任何有趣的内容。没有对异常或错误的引用。
这是最后几个条目,除了日志在run
命令后立即关闭之外,它们看起来无害...
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="22" status="stopping" reason="ok"></response>
<- run -i 23
Log closed at 2019-02-26 17:27:27
其他一些需要注意的事项
该脚本确实迭代了第一个元素,但它立即退出foreach
循环并继续请求的其余部分,将数据返回到视图(但当然只有一个结果,而不是预期的 10 个)
我还在 PhpStorm 2018.3 和 2018.4 上进行了测试,并且行为仍然存在。