You are here: php 5: Static class variables « PHP Programming Language « IT news, forums, messages
php 5: Static class variables

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация