dongpang9573 2011-12-14 18:04 采纳率: 0%
浏览 7
已采纳

PHP对象坏了,$这是未定义的

The code:

<?php

class My_Test{

    public $exists = 'yah';

    public function test(){
            return $this->exists;
    }

}

$test = new My_Test;
echo $test->test();

produces the following error intermittently (every other page request on average) on two servers:

( ! ) Notice: Trying to get property of non-object in test.php on line 8
Call Stack
#   Time    Memory  Function    Location
1   0.0003  636392  {main}( )   ../test.php:0
2   0.0003  636840  My_Test->test( )    ../test.php:14

where line 10 is `return $this->exists;

Please note this is not an untested example, it is the full code that produces the error. I'm aware the code is valid but it doesn't work in two environments.

I'm really not sure why! One server is running PHP 5.3.3 (fedora), the other PHP 5.3.2 (ubuntu). I've tried rebooting the servers too. They don't share anything, although they are on the same network.

Anyone got any tips for debugging?

  • 写回答

3条回答 默认 最新

  • drgbpq5930 2011-12-14 23:55
    关注

    As people before stated the code looks fine and should not cause any errors.

    Therefore I guess it is related to an error of the php engine itself:

    How did you install PHP?

    • Did you compile the sourcecode yourself? Have ./configure or make logged any warnings or error messages while executing?
    • Have you installed PHP by use of a package manager? (I guess everything should be fine then).

    How did you configure PHP?

    • Have you made any changes to php.ini like changing memory limit, paths, etc. ?
    • Have you installed any extension that might cause issues? My experience says often opcode caches (e.g. APC) can cause errors that cannot be easily explained. Also debuggers or other extensions may cause interferences.

    Do you have any (additional) error messages in your HTTP-Daemon-Log?

    • Sometimes additional errors can be found in the error.log file in case the server is configured to do so (e.g. unexpected termination of script or similar).
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab