Posted by marvil07 on July 10, 2009 at 9:17pm
Jump to:
Issue Summary
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 ;-)
<?php
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
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| 0001-Avoid-losing-previous-values-on-static-variables.patch | 2.5 KB | Ignored: Check issue status. | None | None |
Comments
#1
uppss.. bad version :-P
#2
ok, solved on HEAD since all changes in oop branch was included on HEAD
#3
Automatically closed -- issue fixed for 2 weeks with no activity.