note 37427 deleted from language.variables.scope by cmb
| From: | cmb@php.net | Date: | Sun, 27 Oct 2019 08:27:19 +0000 |
| Subject: | note 37427 deleted from language.variables.scope by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212775@lists.php.net to get a copy of this message | ||
Note Submitter: Jack at soinsincere dot com
----
Alright, so you can't set a static variable with a reference.
However, you can set a static variable to an array with an element that is a reference:
<?php
class myReference {
function getOrSet($array = null) {
static $myValue;
if (!$array) {
return $myValue[0]; //Return reference in array
}
$myValue = $array; //Set static variable with array
static $myValue;
}
}
$static = "Dummy";
$dummy = new myReference;
$dummy->getOrSet(array(&$static));
$static = "Test";
print $dummy->getOrSet();
?>