note 102593 modified in language.references.return by danbrown
| From: | danbrown@php.net | Date: | Wed, 23 Feb 2011 15:47:06 +0000 |
| Subject: | note 102593 modified in language.references.return by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177250@lists.php.net to get a copy of this message | ||
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