a simple singleton class (PHP4)
which way is preffered?
// 1.
class Foo {
function getFoo() {
static $instace;
if (!isset($instac e) ) {
$instance = new Foo();
// ...
}
return $instance;
}
}
$foo = Foo::getFoo();
// 2.
class Foo {
function &getFoo() {
static $instace;
if (!isset($instac e) ) {
$instance = new Foo();
// ...
}
return $instance;
}
}
$foo =& Foo::getFoo();
which way is preffered?
// 1.
class Foo {
function getFoo() {
static $instace;
if (!isset($instac e) ) {
$instance = new Foo();
// ...
}
return $instance;
}
}
$foo = Foo::getFoo();
// 2.
class Foo {
function &getFoo() {
static $instace;
if (!isset($instac e) ) {
$instance = new Foo();
// ...
}
return $instance;
}
}
$foo =& Foo::getFoo();
Comment