[php:1:28e0ae4307]
<?php
class Test {
function &factory() {
return new Test;
}
function &singleton() {
static $instance;
if (!isset($instance)) {
$instance =& Test::factory();
}
return $instance;
}
}
$Test1 =& Test::singleton();
$Test1->aaa = 1;
$Test2 =& Test::singleton();
print_r($Test1);
print_r('<br>');
print_r($Test2);
?>
[/php:1:28e0ae4307]
i wyswietla on:
Kod
test Object ( [aaa] => 1 )
test Object ( )
test Object ( )
Dlaczego ?