php - 为什么 var_dump 显示文件名和行号?

标签 php var-dump

就在最近,PHP 中的 var_dump()(目前使用 5.6.23)开始在实际转储我的变量之前打印出文件名和行号。我不知道服务器上有任何重大变化,所以我想知道为什么会发生这种情况,而且在网络或 PHP 文档 ( var_dump() ) 中也找不到任何内容

使用命令行时也会发生奇怪的行为:

 > php -r 'var_dump("lol");'
 Command line code:1:
 string(3) "lol"

虽然我只是习惯于打印“string(3) “lol””。

这不是一个障碍,但打破了我的几个单元测试,我需要比较一些来自使用 var_dump() 打印的 API 的输出。 我最初认为它可能与 xdebug 有关,但找不到任何似乎与此问题相关的指令。

感谢任何导致此问题的提示。

最佳答案

您已启用 xdebug。

One of the new features relates to one of the first things that I added in the original Xdebug: making the var_dump() output "pretty". Xdebug replaces PHP's standard var_dump() function with its own version, as long as the xdebug.overload_var_dump setting is not set to 0


Xdebug 2.3 enhances the overloading of var_dump() with the inclusion of the file name and line number where var_dump() is called at. This has been a long standing feature request.

这是我没有 xdebug 的输出;

>php -r "var_dump('lol')";
string(3) "lol"

https://derickrethans.nl/xdebug-2.3-overload-vardump.html

关于php - 为什么 var_dump 显示文件名和行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38375389/

相关文章:

php - 在上一次插入记录后,MySQL Execute 查询失败

php - 通过URL传递字符串时,$ _ GET方法不起作用

php - 当 ID 未知时保存到表

php - 如何编写与 laravel 相同的 DD() 函数?

c# - PropertyInfo.GetValue(object) 因 IEnumerable<T> [C#, Reflection] 而失败

php - PHP从URL而非表单上传到Youtube

php - 如何根据来自mysql数据库中两个表的数据禁用动态选择框选项

php - var_dump 输出空字符串 - php

php - 字符串和变量的 var_dump() 未显示所需结果

PHP真正的SESSION对象