虚假的PHP未声明的静态属性 [英] Spurious PHP undeclared static property

查看:293
本文介绍了虚假的PHP未声明的静态属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行Debian使用PHP 5.3.x压缩服务器(与Apache和nginx一起发生)我看到随机发生的致命错误未声明的静态属性。通常这是指以下代码:

  class aliro extends aliroBase {
private static $ instance = null;

public static function getInstance(){
return self :: $ instance instanceof self? self :: $ instance :((self :: $ instance = new self());
}
...

并声明 aliro :: $ instance 在上面显示的最后一行未声明(不计算接近的大括号)。然而,这个变量很明显地被宣布为几行。 (确切的错误消息是PHP致命错误:访问未声明的静态属性:aliro :: $ instance in /var/www/apic/public_html/aliro.php在第91行)。



该代码针对服务器的每个请求执行,目前每小时运行约1250个请求。但是错误似乎每小时发生一次。



同时,syslog可能会显示一个suhosin错误消息:

  Oct 22 11:29:45 apic suhosin [20764]:ALERT-SIMULATION  -  
canf不匹配efree() - 在0x2ec9118检测到堆溢出

或内核错误,例如:

  10月22日10:29:43 apic内核:[83469.382141] php [9479]一般保护
ip:6a8161 sp:7fffa270ec20错误:0在php5 [400000 + 6f9000]

  29:45 apic kernel:[79871.245018] php [705]:segfault at 27f2298 
ip 00007f24229e640e sp 00007fff13aca388错误6在
libc-2.11.2.so [7f2422968000 + 158000]

Cron每五分钟运行一次即可触发munin-node,但错误只发生一次。可能是什么原因造成的?



不可重复的是,不清楚可以做些什么,虽然错误造成数据损坏的风险。任何建议?

解决方案

此代码不是(至少不应该是问题)。我会检查代码的其他部分,你可以从aliro类外面引用aliro :: $ instance。 $ instance为private将触发您的精确错误抛出(未声明的静态属性),如果您尝试触摸它外面的类。我会改变它保护(我也讨厌私有属性,他们很少需要是私人而不是保护) - 这将给出更好的错误信息(你正在尝试访问不公开的属性),我认为它应该给你发现文件和行。


Running Debian Squeeze servers with PHP 5.3.x (happens with both Apache and nginx) I'm seeing random occurrences of the fatal error undeclared static property. Often this refers to the following code:

class aliro extends aliroBase {
        private static $instance = null;

        public static function getInstance () {
            return self::$instance instanceof self ? self::$instance : (self::$instance = new self());
        }
...

and states that aliro::$instance is undeclared on the last line shown above (not counting the close curly bracket). Yet the variable is quite plainly declared just a couple of lines earlier. (The exact error message is "PHP Fatal error: Access to undeclared static property: aliro::$instance in /var/www/apic/public_html/aliro.php on line 91").

This code is executed for every request to the server, which is currently running about 1,250 requests per hour. But the error appears to occur once an hour.

Simultaneously, syslog may show a suhosin error message:

Oct 22 11:29:45 apic suhosin[20764]: ALERT-SIMULATION - 
canary mismatch on efree() - heap overflow detected at 0x2ec9118

or a kernel error, such as:

Oct 22 10:29:43 apic kernel: [83469.382141] php[9479] general protection 
ip:6a8161 sp:7fffa270ec20 error:0 in php5[400000+6f9000]

or

Oct 22 09:29:45 apic kernel: [79871.245018] php[705]: segfault at 27f2298 
ip 00007f24229e640e sp 00007fff13aca388 error 6 in 
libc-2.11.2.so[7f2422968000+158000]

Cron is running every five minutes to trigger munin-node, but the errors only occur once an hour. What could be causing this?

Being non-repeatable, it isn't clear what can be done, although the errors are creating a risk of data corruption. Any suggestions?

解决方案

This code isn't (at least shouldn't be the issue). I would check for other part of the code, where you might refer to aliro::$instance from outside aliro class. $instance being private would trigger your exact error thrown (undeclared static property) if you try to touch it outside of the class. I would change it to protected (I also hate private properties, they rarely NEED to be private instead of protected) - that would give better error message (that you are trying to access property that is not public), also I think it should give you the file and line it occures.

这篇关于虚假的PHP未声明的静态属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆