I'm getting a rather strange intermittent error on a webapp I'm working on, that only triggers after certain circumstances. Once a particularly long processing page is executed (running through, retrieving and sorting 100000+ records), every page load since is failing with several errors like the following on any of the singleton objects used:
PHP Warning: Attempt to assign property of non-object in E:\tracking\lib\Controller\ControllerChainManager.class.php on line 33
The relevant section of code is as follows: (Line 33 marked with an arrow).
class ControllerManager {
private static $Instance;
private $CurrentController = 0;
private $ControllerArray;
private $ControllerArrayIndex = 0;
/**
* Constructor
* @return null;
*/
private function __construct() {
$this->ControllerArray = array(); <-- LINE 33
return;
}
/**
* Singleton instance function
* @return ControllerManager;
*/
public static function Inst() {
if (!isset(self::$Instance)) {
$c = __CLASS__;
self::$Instance = new $c;
}
return self::$Instance;
}
//*** snip the rest of the class definition ***
Now, this file is included in every request, but once the bad request is made, these errors will keep occurring (eventually leading to fatal errors down the line) until the Apache server restarts. If the same request is made using a smaller data set, the error doesn't occur and the system carries on as normal.
Nothing seems to be turning up as relevant searching on the error text given, and the fact that the problem is failing only on singleton-pattern instances might be a clue, but I can't for the life of me figure what's going on.
Server is PHP 5.3.
Anyone ever seen an error like this before? It's somewhat stumping me.
Edit: An additional trawling through the logs is now revealing another class showing this error, but it's NOT a singleton this time.
class ControllerChainData {
public $Action;
public $Controller;
public $Vars;
public function __construct($controller,$action,$vars = null) {
$this->Controller = $controller; //<-- 10
$this->Action = $action; //<-- 11
$this->Vars = $vars; //<-- 12
}
}
Resulting in...
PHP Warning: Attempt to assign property of non-object in E:\tracking\lib\Controller\ControllerChainManager.class.php on line 10
PHP Warning: Attempt to assign property of non-object in E:\tracking\lib\Controller\ControllerChainManager.class.php on line 11
PHP Warning: Attempt to assign property of non-object in E:\tracking\lib\Controller\ControllerChainManager.class.php on line 12
whenever an object of class ControllerChainData is instantiated.
Edit 2: In response to a comment below, CCD is called from the following method of the ControllerChainManager class:
public function RegisterControllerIntoChain ($controller, $action, $vars = null) {
$contpath = 'controllers/' . $controller . '/' . $controller . '.cont.php';
if (file_exists($contpath)) {
include_once($contpath);
$this->ControllerArray[$this->ControllerArrayIndex++] = new ControllerChainData($controller,$action,$vars);
return true;
}
return false;
}
Edit 3: Looks like this previous stackOverflow post is relevant / may be the same bug:
Non-deterministic object reference bug in PHP 5.3.X
Edit 3a:
This error report is describing my exact problem: http://bugs.php.net/bug.php?id=50027 (found from prior SO post) I'm going to update PHP on the server as soon as possible, I'll post information on if this solves the problem.