note 18905 added to language.variables.scope

From: Date: Sat, 09 Feb 2002 09:41:07 +0000
Subject: note 18905 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-26401@lists.php.net to get a copy of this message
I'm using PHP 4.1.1 While designing a database access class, I needed a static variable that will be incremented for all instances of the class each time the class connected to the database. The obvious solution was to declare a "connection" class variable with static scope. Unfortunatly, php doesn't allow such a declaration. So I went back to defining a static variable in the connect method of my class. But it seems that the static scope is not inherited: if class "a" inherit the "db access" class, then the "connection" variable is shared among "a" instances, not among both "a" AND "db access" instances. Solution is to declare the static variable out of the db access class, and declare "global" said variable in the connect method. -- http://www.php.net/manual/en/language.variables.scope.php http://master.php.net/manage/user-notes.php?action=edit+18905 http://master.php.net/manage/user-notes.php?action=delete+18905 http://master.php.net/manage/user-notes.php?action=reject+18905

« previous php.notes (#26401) next »