note 73822 deleted from language.variables.scope by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 01:34:16 +0000 |
| Subject: | note 73822 deleted from language.variables.scope by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155553@lists.php.net to get a copy of this message | ||
Note Submitter:
----
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.