I discovered this very strange bug on our websites. The web site has labored correctly for around annually now, however yesterday out of the blue it began tossing "ramdom" 500 errors, statig for instance that $this isn't an item, or perhaps an include fails at random (which shoud not have access to unsuccessful regardless).

An example of code:

     //class Enviroment    
     219 public function run()
     220 {
     221  //vložit prostředí
     222  if (class_exists('CONFIG')) {
     223   $this->dir_basic = Config::$DirBasic;
     224  }
     225  include_once($this->dir_basic . 'web/libsf/enviroment/types/' . ($this->mode == 'dev' ? 'dev' : 'prod') . '.php');
     227  //vytvořit třídu prostředí
     228  $enviroment_class = 'Enviroment' . $this->mode;
     229  $this->enviroment = new $enviroment_class($this);
     230  $this->enviroment->pre_libs();
     232  //načíst knihovny
     233  $this->load_libs();
     235  //zavolat inicializační metody po načtení knihoven
     236  $this->enviroment->post_libs();
     238  $this->init_vars();
     239 }

These kinds is started correctly, throught this (this EXACT code creates A number of our websites, just that one eliminate out of the blue):

$aplication = Enviroment::get_aplication('prod');

This throws the next errors (note the road amounts):

Notice: Trying to get property of non-object in /var/www/vhosts/e/example.cz/data/www/web/libsf/enviroment/enviroment.php on line 225
Notice: Trying to get property of non-object in /var/www/vhosts/e/example.cz/data/www/web/libsf/enviroment/enviroment.php on line 228
Notice: Trying to get property of non-object in /var/www/vhosts/e/example.cz/data/www/web/libsf/enviroment/enviroment.php on line 230
Fatal error: Call to a member function pre_libs() on a non-object in /var/www/vhosts/e/example.cz/data/www/web/libsf/enviroment/enviroment.php on line 230

(In my opinion the include online 225 fails because $this really is "no object"...). I am running PHP5.3.3 on CentOS 5.5. After I restart apache, everything appears to operate okay for some time (5 minutes, two hrs, seven seconds...) after which it begins tossing these errors again.

Any help appreciated.

EDIT: Enviroment class constructor:

private function __construct($mode)
  $this->mode = $mode;

  //vygenerovat unikátní hash
  mt_srand((double) microtime() * 1000000);
  $this->hash = md5(uniqid(mt_rand(), TRUE)) . rand(0, 99999999);

Get_application method:

 public static function get_aplication($mode = 'auto')
  if ($mode == 'auto') {
   //nastavit produkční mod
   $mode = 'prod';

   //rozpoznat typ developerského módu
   if ($_SERVER['SERVER_ADDR'] == '' || preg_match('/^localhost/', $_SERVER['HTTP_HOST']) || $_GET['env_mode'] == 'developer') {
    $mode = 'dev';
  return self::$enviroment_obj = new Enviroment($mode);

Once the error happens, do echo for:

1)$this->dir_basic . 'web/libsf/enviroment/types/' . ($this->mode == 'dev' ? 'dev' : 'prod') . '.php'

2)'Enviroment' . $this->mode;

See if the created strings are what you'd expect these to be.

Also make certain the file you are attempting to include really is available.