Re: Static method variable
| From: | Thijs Lensselink | Date: | Thu, 18 Sep 2008 13:35:10 +0000 |
| Subject: | Re: Static method variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-280436@lists.php.net to get a copy of this message | ||
Quoting Christoph Boget <christoph.boget@gmail.com>:
Perhaps I'm misunderstanding what a static method variable is supposed to do. I thought the value would be static for an class' instance but it appears it is static across all instances of the class. Consider: class StaticTest { public function __construct() { } public function test( $newVal ) {That's exactly how a static class var functions. It's available cross all instances of the class.static $retval = '';if( $retval == '' ) { $retval = $newVal; } echo $retval . '<br>';} } $one = new StaticTest(); $one->test( 'joe' ); $two = new StaticTest(); $two->test( 'bob' ); Should it be working that way? thnx, Chris