It seems like a httpd process does not hold the static variable in the memory even after the execution or multiple httpd processes do not share the same static variable allocated in the memory. So to me, it does not make any difference between the global and the static variables that are initialized only once throughout the file.
<?
class Singlton
{
function Singlton()
{
}
function getInstance()
{
// static variable only accessable by this method
static $onlyInstance;
if(!isset($onlyInstance))
{
$onlyInstance = new Singlton();
}
return $onlyInstance;
}
}
?>
or
<?
// global variable accessable from anywhere
$_SINGLTON_INSTANCE;
class Singlton
{
function Singlton()
{
}
function getInstance()
{
global $_SINGLTON_INSTANCE;
if(!isset($_SINGLTON_INSTANCE))
{
$_SINGLTON_INSTANCE = new Singlton();
}
return $_SINGLTON_INSTANCE;
}
}
?>
The above examples are pretty much the same to me except that the $onlyInstance is only accessable by invoking the Singlton::getInstance() while $_SINGLTON_INSTANCE can be accessed anywhere. So I guess it's just up to the programmers how it should be designed (the scope issues).
Please let me know if you know more about Zend Engine for PHP 4 about this.