From: falkon1313 at gmail dot com
Operating system: Any
PHP version: 5.2.10
PHP Bug Type: Class/Object related
Bug description: Incorrect scope for static variables in object methods
Description:
------------
When a variable is declared static within an object method, it's scope is
spread across all instantiated objects of the class.
This is not a static class variable, nor is it in a static class method,
it is in a method that requires an instantiated object, operates within the
context of that object, and should have the object scope.
Reproduce code:
---------------
<?php
class TestClass {
public function test($val = NULL) {
static $stored = 'empty';
if ($val) {
$stored = $val;
}
return $stored;
}
}
$a = new TestClass();
echo $a->test() ."\n";
echo $a->test('alpha') ."\n";
$b = new TestClass();
echo $b->test() ."\n";
echo $b->test('bravo') ."\n";
echo $a->test() ."\n";
Expected result:
----------------
empty
alpha
empty
bravo
alpha
Actual result:
--------------
empty
alpha
alpha
bravo
bravo
--
Edit bug report at http://bugs.php.net/?id=48623&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=48623&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=48623&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=48623&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=48623&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=48623&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=48623&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=48623&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=48623&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=48623&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=48623&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=48623&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=48623&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=48623&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=48623&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48623&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48623&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=48623&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=48623&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=48623&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=48623&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=48623&r=mysqlcfg