Re: Static method variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If you're looking for a persistent variable in one class instance, then
you need a member variable.  If you want it persistent across all class
instances, you want a static variable.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Christoph Boget wrote:
> 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 )
>   {
>     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
>
>   

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux