PHP variables randomly becomes NULL -


for quite while experience weird problem our hosting server. once while (seems randomly) variables in php become nulls.

in general works fine, once while happens. accounts on server affected , php apps (including phpmyadmin, wordpress our own scripts). contacted our hosting company, unable find solution.

i had few ideas, promising 1 issue suhosin. not message in log directly it.

we made simplest possible script reproduce error:

<?php class example {      protected $stringvar = 'this string value';      public function accessparameter()     {         $error = false;         if (isset($this->stringvar) && !is_null($this->stringvar)) {             echo "string var : " . $this->tostringwithtype($this->stringvar) . "\n";         } else {             echo "string var not set\n";             $error = true;         }          if ($error) {             $logfile = dirname(__file__)."/random_bug_log.log";             file_put_contents($logfile, date('y-m-d h:i:s')."\n", file_append);             file_put_contents($logfile, $this->tostringwithtype($this->stringvar) . "\n", file_append);         }     }      public function tostringwithtype($var)     {         $type = gettype($var);         return "($type) '$var'";     }  }  $e = new example(); $e->accessparameter(); 

normal output:

string var : (string) 'this string value'  

output when weird thing happens:

string var not set 

i open ideas or suggestions how solve problem. guess ultimate solution change hosting company. did not manage create issue on localhost or other server.


test piece have been made, including suggestions:

<?php class example {   protected $stringvar = 'this string value';    public function accessparameter() {     $error = false;     if(isset($this->stringvar) && !is_null($this->stringvar)) {       echo "string var : "     .$this->tostringwithtype($this->stringvar)     ."\n";     } else {       echo "string var not set\n";       $error = true;     }      if($error) {       $logfile = dirname(__file__)."/random_bug_log.log";       file_put_contents($logfile, date('y-m-d h:i:s')."   ", file_append);       file_put_contents($logfile,              $this->tostringwithtype($this->stringvar) . "\n",             file_append);     }    }    public function writeparameter() {     $this->stringvar="variable assigned";     if(isset($this->stringvar) && !is_null($this->stringvar)) {       echo "string var : "     .$this->tostringwithtype($this->stringvar)     ."\n";     } else {       echo "string var not set\n";       $error = true;     }   }    public function tostringwithtype($var)   {     $type = gettype($var);     return "($type) '$var'";   }   }  $e = new example(); $e->accessparameter(); $e->writeparameter(); 

the output while thing happens:

string var not set string var not set 

it strange problem.

it may not solution worth try;

protected $stringvar;  function __construct() {     $this->stringvar = 'this string value'; } 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -