From: [EMAIL PROTECTED]
Operating system: Windows 2000
PHP version: 4.1.1
PHP Bug Type: Class/Object related
Bug description: Static variables into class member funtions have wrong scope
Static variables inside member functions of a classes have wrong scope.
They should belong to each instance of a class, like normal class
properties, but they're belong to class definition instead and, therefore,
shared between every instance of this class. It makes static variables
unusable into class member variables.
Here is an example:
// Define class
class A
{
var $id = null;
function A($id)
{
$this->id = $id;
}
function func()
{
// Here we have counter into static variable
static $cnt;
if (!$cnt)
$cnt = 0;
// Show counter value and ID of a class instance
echo $this->id.": ".($cnt++)."\n";
}
};
// Create 2 instances of our class with different IDs
$a = new A('A');
$b = new A('B');
// Call method of each class instance twice and see,
// what will happen
$a->func();
$b->func();
$a->func();
$b->func();
Expected results:
-----------------
A: 0
B: 0
A: 1
B: 1
Actual results:
---------------
A: 0
B: 1
A: 2
B: 3
--
Edit bug report at http://bugs.php.net/?id=16245&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=16245&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=16245&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=16245&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=16245&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=16245&r=support
Expected behavior: http://bugs.php.net/fix.php?id=16245&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=16245&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=16245&r=submittedtwice