Hi,
I have discovered some odd behavior with static variables, and wonder if it is a bug. In both PHP4 and PHP5, the code below prints:
not registered, class pear_common not registered, class archive_tar
I.e., because the PEAR function is called with $this->PEAR(), the static variable is reset as if the PEAR() function were re-defined! Is this expected behavior? I was under the impression that static declared a per-class static variable.
<?php
class PEAR {
function PEAR($error_class = null)
{
static $registered = false;
$classname = get_class($this);
while ($classname && strcasecmp($classname, "pear")) {
$destructor = "_$classname";
if (method_exists($this, $destructor)) {
if (!$registered) {
echo 'not registered, class ' . get_class($this) . "\n";
$registered = true;
}
break;
}
}
}
}
class PEAR_Common extends PEAR { function PEAR_Common() { $this->PEAR(); }
function _PEAR_Common() { } }
class Archive_Tar extends PEAR { function Archive_Tar() { $this->PEAR(); }
function _Archive_Tar() { } }
$a = &new PEAR; $b = &new PEAR_Common; $c = &new Archive_Tar; ?>
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php