note 92215 deleted from language.references by cmb
| From: | cmb@php.net | Date: | Sun, 01 Sep 2019 07:53:47 +0000 |
| Subject: | note 92215 deleted from language.references by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212072@lists.php.net to get a copy of this message | ||
Note Submitter: wernerdegroot at nospam dot gmail
----
In the following case you don't have to use = & operator when returning a reference:
<?php
class a {
public $a = 1;
}
class b {
static $var;
public static function & gvar($i) {
if(!(isset(b::$var[$i]))) {
b::$var[$i] = new a;
}
return b::$var[$i];
}
}
$b = new b;
$a = b::gvar(1);
$a->a = 14;
$c = b::gvar(1);
echo $c->a; // 14
?>
Note the $a = b::gvar(1) instead of $a = & b::gvar(1)!!!