note 98577 added to language.variables.scope
| From: | jakub dot lopuszanski at nasza-klasa dot pl | Date: | Thu, 24 Jun 2010 09:59:22 +0000 |
| Subject: | note 98577 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170391@lists.php.net to get a copy of this message | ||
If you use __autoload function to load classes' definitons, beware that "static local
variables are resolved at compile time" (whatever it really means) and the order in which
autoloads occur may impact the semantic.
For example if you have:
<?php
class Singleton{
static public function get_instance(){
static $instance = null;
if($instance === null){
$instance = new static();
}
return $instance;
}
}
?>
and two separate files A.php and B.php:
class A extends Singleton{}
class B extends A{}
then depending on the order in which you access those two classes, and consequently, the order in
which __autoload includes them, you can get strange results of calling B::get_instance() and
A::get_instance().
It seems that static local variables are alocated in as many copies as there are classes that
inherit a method at the time of inclusion of parsing Singleton.
----
Server IP: 69.147.83.197
Probable Submitter: 195.88.186.3
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/98577
Del: integrated -- https://master.php.net/note/delete/98577/integrated
Del: useless -- https://master.php.net/note/delete/98577/useless
Del: bad code -- https://master.php.net/note/delete/98577/bad+code
Del: spam -- https://master.php.net/note/delete/98577/spam
Del: non-english -- https://master.php.net/note/delete/98577/non-english
Del: in docs -- https://master.php.net/note/delete/98577/in+docs
Del: other reasons-- https://master.php.net/note/delete/98577
Reject -- https://master.php.net/note/reject/98577
Search -- https://master.php.net/manage/user-notes.php