Posted by joes on 10/14/05 23:06
Hi folks!
I noticed in my static example which I did in PHP that the static
variable is not stored over multiple php pages. So this does differ
than to other OO languages like JSP. Is this so or did I something
wrong?
MyClass.php:
<?
class MyClass
{
static $MyVar = 123;
function getMyVar()
{ return MyClass::$MyVar; }
}
?>
1. Call on my server
MyPage1.php
<?
require("MyClass.php");
// set here the value
MyClass::$MyVar = 456;
echo MyClass::$MyVar; // prints 456
myInst1 = new MyClass();
echo myInst1->getMyVar(); // prints 456
?>
2. Call on my server
MyPage2.php
<?
require("MyClass.php");
myInst2 = new MyClass();
echo myInst2->getMyVar(); // prints 123 ??? Expected was 456
?>
Thanks
Mark Egloff
[Back to original message]
|