If we initialize each time the variable, we lose previous changes, so for example cache variables are retrieved every call.
This patch tries to solve it.
Here is also a quick php test for structured and OO ;-)
function load() {
return array(1,2,3);
}
class a {
private static $cache;
public function get() {
if (!isset(self::$cache)) {
echo "cache __NOT__ set";
self::$cache = load();
}
else {
echo "cache set";
}
return self::$cache;
}
}
$obj = new a();
$arr = $obj->get();
$arr = $obj->get();
var_dump($arr);
echo "<hr>";
function sget() {
// without refering the variable with static again it's considered a new variable, not our static one
static $scache;
if (!isset($scache)) {
echo "cache __NOT__ set";
$scache = load();
}
else {
echo "cache set";
}
return $scache;
}
$arr2 = sget();
$arr2 = sget();
var_dump($arr2);
Also, already applied to my master branch if you want to pull :-D
Comments
Comment #1
marvil07 commenteduppss.. bad version :-P
Comment #2
marvil07 commentedok, solved on HEAD since all changes in oop branch was included on HEAD