PHP static member not holding value
-
Hi i have a strange problem with a WordPress plugin that i am writing, but this isnt about WordPress per se and more to do with PHP so please read on so I can explain. The WordPress plugin is hooked up so that the init() function gets called… this works i can confirm it gets called once.
class MyClass
{
static $i=0;public static function init()
{
self::$i++;
}public static function dosomething()
{
echo ‘i is = ‘ . self::$i;
}
}When callinf dosomething() for the first time from within WordPress it is ok. I then have another ajax-response.php file which includes the above class and again calls dosomething, which prints the i value = 1.
The problem is the i value when calling via the ajax-response.php script is back to 0?
Its as if it is executing in a totally different memory space and creating a new program, such that static member variables are only shared between same process as opposed to multiple web threads.
Any ideas?
Thanks in advance,
Chris
- The topic ‘PHP static member not holding value’ is closed to new replies.