|
-
Jan 1st, 2007, 03:43 AM
#1
[RESLOVED] Class initialisation.
Is it possible to do class initialisation (as opposed to a constructor) in PHP?
Last edited by penagate; Jan 1st, 2007 at 08:11 AM.
-
Jan 1st, 2007, 06:14 AM
#2
Re: Class initialisation.
What do you mean? Initialize a static class?
-
Jan 1st, 2007, 07:05 AM
#3
Re: Class initialisation.
A member function that gets called when the class is first loaded.
-
Jan 1st, 2007, 07:20 AM
#4
Re: Class initialisation.
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();
-
Jan 1st, 2007, 07:20 AM
#5
Re: Class initialisation.
Yeah, that's the idea; just wondered if there was a magic function for it.
-
Jan 1st, 2007, 07:29 AM
#6
Re: Class initialisation.
 Originally Posted by penagate
Yeah, that's the idea; just wondered if there was a magic function for it.
I think its called __doItYourSelf() 
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.
-
Jan 1st, 2007, 07:33 AM
#7
Re: Class initialisation.
Unloading's not important. Not yet, at least.
Thanks anyway.
-
Jan 1st, 2007, 07:35 AM
#8
Re: Class initialisation.
Now get a life and stop coding on new years day
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|