note 73822 added to language.variables.scope
| From: | php-general at lists dot php dot net | Date: | Mon, 12 Mar 2007 08:13:58 +0000 |
| Subject: | note 73822 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124364@lists.php.net to get a copy of this message | ||
addendum to warhog at warhog dot net
about static variables within methods
<?php
class A
{
function incStaticVar()
{
static $var = 0;
$var++;
return $var;
}
}
class B extends A
{
}
$a =& new A();
$b =& new B();
print_r(array(
$a->incStaticVar(),
$b->incStaticVar(),
$a->incStaticVar(),
));
?>
expected result
Array
(
[0] => 1
[1] => 2
[2] => 3
)
real result
Array
(
[0] => 1
[1] => 1
[2] => 2
)
So I conclude that the PHP5 duplicates methods for each inherited classes.
----
Server IP: 69.147.83.197
Probable Submitter: 80.69.145.254
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/73822
Del: integrated -- https://master.php.net/note/delete/73822/integrated
Del: useless -- https://master.php.net/note/delete/73822/useless
Del: bad code -- https://master.php.net/note/delete/73822/bad+code
Del: spam -- https://master.php.net/note/delete/73822/spam
Del: non-english -- https://master.php.net/note/delete/73822/non-english
Del: in docs -- https://master.php.net/note/delete/73822/in+docs
Del: other reasons-- https://master.php.net/note/delete/73822
Reject -- https://master.php.net/note/reject/73822
Search -- https://master.php.net/manage/user-notes.php