Re: Re: Strange behaviour of static declared content.

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

 



Colin Guthrie wrote:
PS I know the above examples are contrived and that constructors would
be more appropriate for the above - but using constructors is not always
possible due to how you deal with failed initialisations where
exceptions are not desirable.

I see what you mean. You thought that static variables in a member function of a class would be different for each instance of that class. Indeed that's not the case, statics are attached to the class not the object.

As for the problem of dealing with failed initialisations there are two ways to deal with that. The first is to us a separate initialisation method - this allows it to return a value. Your constructor would simply fill the object with sensible defaults.

The second is to have a member variable that stores whether the object has been successfully initialised. Either of these would be far better than using a static variable since initialisation status is a property of the object not the class.

Anyways, glad we both understand some things a bit better now. On to the next problem!

-Stut

--
http://stut.net/

--
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