View Single Post
Old Jan 14th, 2005, 10:09 PM   #1
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Simulate Static Class Variable...

Here is a little trick you can use to simulate static variables within a PHP class. PHP5 does not yet support static variables, though it does have support for static class functions.

$GLOBALS['_transient']['static']['test']->v1 = 1;
 
class Test {
 
    function Test() {
        $this->v1 = & $GLOBALS['_transient']['static']['test']->v1;
    }
 
    function printAndIncrease() {
        echo "$this->v1<br>";
        $this->v1++;
    }
 
    var $v1;
}
 
$t1 = new Test();
$t1->printAndIncrease();
$t2 = new Test();
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote