note 118079 added to language.variables.scope
| From: | nino dot skopac at gmail dot com | Date: | Wed, 30 Sep 2015 08:01:08 +0000 |
| Subject: | note 118079 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203880@lists.php.net to get a copy of this message | ||
Interesting behavior in PHP 5.6.12 and PHP 7 RC3:
<?php
class Foo {
public function Bar() {
static $var = 0;
return ++$var;
}
}
$Foo_instance = new Foo;
print $Foo_instance->Bar(); // prints 1
print PHP_EOL;
unset($Foo_instance);
$Foo_instance2 = new Foo;
print $Foo_instance2->Bar(); // prints 2
print PHP_EOL;
?>
How can a 2 be printed, since we unseted the whole instance before?
Consider a similar example:
<?php
class Foo {
public static $var = 0;
public static function Bar() {
return ++self::$var;
}
}
$Foo_instance = new Foo;
print $Foo_instance->Bar(); // prints 1
print PHP_EOL;
unset($Foo_instance);
$Foo_instance2 = new Foo;
print $Foo_instance2->Bar(); // prints 2
print PHP_EOL;
?>
No idea why is this happening.
----
Server IP: 72.52.91.14
Probable Submitter: 78.0.1.9
----
Manual Page -- http://php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/118079
Del: integrated -- https://master.php.net/note/delete/118079/integrated
Del: useless -- https://master.php.net/note/delete/118079/useless
Del: bad code -- https://master.php.net/note/delete/118079/bad+code
Del: spam -- https://master.php.net/note/delete/118079/spam
Del: non-english -- https://master.php.net/note/delete/118079/non-english
Del: in docs -- https://master.php.net/note/delete/118079/in+docs
Del: other reasons-- https://master.php.net/note/delete/118079
Reject -- https://master.php.net/note/reject/118079
Search -- https://master.php.net/manage/user-notes.php