Re: is there a static constructor?

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

 



On 31 March 2011 06:56, D. Dante Lorenso <dante@xxxxxxxxxxx> wrote:
> All,
>
> I want to build a config file class that gets called statically. ÂIs there
> such a thing as a static constructor? ÂExample:
>
> class Daz_Config {
> Âpublic static function load() {
> Â Â...
> Â}
> Âpublic static function get($key) {
> Â Âself :: load();
> Â Â...
> Â}
> }
>
> Daz_Config :: get('myvalue');
>
> I want to call the load function when the class is used for the first time.
> ÂIf no code ever calls "Daz_Config :: get(...)" then I never want to invoke
> load() but if it does get called, I only want to call load() once before the
> class is used further.
>
> Anyone know how to do this with calling load() at the top of all the other
> functions and writing a load() function that exits early if already loaded?
>

The concept doesn't really make sense - a class that never gets
instantiated never gets constructed, hence no static constructor (nor
a static destructor). You'll have to call your "constructor" function
at the top of the static methods you'll be using - just check inside
the constructor if it's been called before or not.

Regards
Peter


-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

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