Is it possible to do class initialisation (as opposed to a constructor) in PHP?
Printable View
Is it possible to do class initialisation (as opposed to a constructor) in PHP?
What do you mean? Initialize a static class? :confused:
A member function that gets called when the class is first loaded.
The class isn't really loaded in PHP as far as I am aware. I suppose what you can do is have a function that is called imeaditaley after the class definition:
PHP Code:class Poo
{
private static $var;
public static init()
{
self::$var = 'poo';
}
}
Poo::init();
Yeah, that's the idea; just wondered if there was a magic function for it.
I think its called __doItYourSelf() ;)Quote:
Originally Posted by penagate
The class is loaded when interpreter runs over it so it would seem quite logical to call an init() method immediatly after its definition. As for unloading the class - I suppose you could resister a shutdown function but you would need to check that all instances of the object have been destroyed. Not sure how you do that.
Unloading's not important. Not yet, at least.
Thanks anyway.
Now get a life and stop coding on new years day :p