简体   繁体   English

@ -sign在Ubuntu 12,php5和xdebug中

[英]@-sign in Ubuntu 12, php5 and xdebug

I develop in Vagrant VM with Ubuntu 12.04 and php 5.5.7. 我使用Ubuntu 12.04和php 5.5.7在Vagrant VM中开发。 and faced problem of incorrect error reporting handling in this case: @-sign works incorrectly. 并且在这种情况下遇到错误报告处理错误的问题:@ -sign工作不正确。

When using custom error handlers and globally turned on error reporting, @-calls (such as @unlink('...') ) should trigger custom handler but calling error_reporting() from it should return 0 in this case: 当使用自定义错误处理程序并全局启用错误报告时,@ @unlink('...') (例如@unlink('...') )应该触发自定义处理程序,但在这种情况下从它调用error_reporting()应返回0:

http://ca3.php.net/manual/en/language.operators.errorcontrol.php http://ca3.php.net/manual/en/language.operators.errorcontrol.php

If you have set a custom error handler function with set_error_handler() then it will still get called, but this custom error handler can (and should) call error_reporting() which will return 0 when the call that triggered the error was preceded by an @. 如果你用set_error_handler()设置了自定义错误处理函数,那么它仍然会被调用,但是这个自定义错误处理程序可以(并且应该)调用error_reporting(),当触发错误的调用前面有一个@时,它将返回0 。

But in fact it returns -1! 但实际上它返回-1!

Googling have not resulted in anything. 谷歌搜索没有任何结果。

Have anyone any idea, how to make it work correctly? 有谁知道如何使它正常工作? And what can cause this? 什么可以导致这个?

UPD UPD

The question is not about using or not using of @-sign. 问题不在于使用或不使用@ -sign。 Even if I don't use it, vendors of third-party packages use it. 即使我不使用它,第三方软件包的供应商也会使用它。 And don't tell me that this packages are bad because of it, you will be wrong. 并且不要告诉我这个包因此而坏,你会错的。 In some situations, when using @ wisely, it can fix issues caused by bad design of old native php functions that produce warnings in places where they should not. 在某些情况下,当明智地使用@时,它可以解决由于旧的本机php函数的错误设计而导致的问题,这些问题在不应该出现的地方产生警告。 But this is a hollywar and doesn't matter in question context. 但这是一场虚幻的战争,在问题上下文中都没有关系。

The question is about making it work correctly in given environment and localization of issue source 问题是要使其在给定的环境中正常运行以及问题源的本地化

UPD2 UPD2

Problem was found, see accepted answer 发现问题,请参见接受的答案

From php.net , WARNING message 来自php.net ,警告消息

Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. 目前,“@”错误控制运算符前缀甚至会禁用将终止脚本执行的严重错误的错误报告。 Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why . 除此之外,这意味着如果你使用“@”来抑制来自某个函数的错误,并且它不可用或者输入错误, 那么脚本就会在那里死亡而没有任何关于原因的指示

Is equialent: 等价:

error_reporting(0);
unlink('...'); // and error reporting always return 0
error_reporting(E_ALL);

If you want to process the unlink, you must to check that file exists before unlink it 如果要处理取消链接,则必须在取消链接之前检查该文件是否存在

$file = 'path/to/file.txt';
if(file_exists($file))
{
   unlink($file);
}

PS Don't use "@" - it is very bad code style and bad solution by performance. PS不要使用“@” - 这是非常糟糕的代码风格和糟糕的性能解决方案。 See the test with @ and without it 使用@ 查看测试 ,没有它

If you're wondering what the performance impact of using the @ operator is, consider this example. 如果您想知道使用@运算符对性能产生的影响,请考虑此示例。 Here, the second script (using the @ operator) takes 1.75x as long to execute...almost double the time of the first script. 在这里,第二个脚本(使用@运算符)执行时间长达1.75倍......几乎是第一个脚本时间的两倍。

So while yes, there is some overhead, per iteration, we see that the @ operator added only .005 ms per call. 因此,虽然是,但每次迭代都有一些开销,我们看到@运算符每次调用仅添加.005毫秒。 Not reason enough, imho, to avoid using the @ operator. 恕我直言,没有足够的理由避免使用@运算符。

Without "@" 不带“ @”

for ($i = 0; $i < 1000000; $i++) { $undefined; }

real   0m7.617s
user   0m6.788s
sys    0m0.792s

And with "@" 与 ”@”

for ($i = 0; $i < 1000000; $i++) { @$undefined; }

real   0m13.333s
user   0m12.437s
sys    0m0.836s

Well, I've found the problem... Xdebug is installed, and the problem is there. 好吧,我发现了问题......安装了Xdebug,问题出现了。

Xdebug docs say: Xdebug文档说:

xdebug.scream xdebug.scream

Type: boolean, Default value: 0 , Introduced in Xdebug >= 2.1 类型:布尔值, 默认值:0 ,在Xdebug> = 2.1中引入

If this setting is 1, then Xdebug will disable the @ (shut-up) operator so that notices, warnings and errors are no longer hidden. 如果此设置为1,则Xdebug将禁用@(关闭)运算符,以便不再隐藏通知,警告和错误。

But by some reason, after installing it via apt-get install -y php5-xdebug it sets scream to 1 in /etc/php5/mods-available/xdebug.ini 但由于某种原因,在通过apt-get install -y php5-xdebug后,它在/etc/php5/mods-available/xdebug.ini apt-get install -y php5-xdebug scream设置为1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM