note 102593 modified in language.references.return by danbrown
[email protected] Wed, 23 Feb 2011 07:47:06 -0800
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
Keep in mind that returning by reference doesn't work with __callStatic:
<?php
class Test {
private static $_inst;
public static function & __callStatic ($name, $args) {
if (!isset(static::$_inst)){
echo "create";
static::$_inst = (object)"test";
}
return static::$_inst;
}
var_dump($a = &Test::abc()); // prints 'create'
$a = null;
var_dump(Test::abc()); // doesn't prints and the instance still exists in Test::$_inst
?>
--was--
Keep in mind that returning by reference doesn't work with __callStatic:
class Test {
private static $_inst;
public static function & __callStatic ($name, $args) {
if (!isset(static::$_inst)){
echo "create";
static::$_inst = (object)"test";
}
return static::$_inst;
}
var_dump($a = &Test::abc()); // prints 'create'
$a = null;
var_dump(Test::abc()); // doesn't prints and the instance still exists in Test::$_inst
http://php.net/manual/en/language.references.return.php