Re: [PHP] getting name of class from a parent
Rory Browne wrote: > You may be wondering why I don't just " $instance = new utility_class > " - the reason is that I want to only create one of these instances. I > don't want any more than one instance of utility_class at any one > time. > > I can't use get_class($this) either, because, there is no $this when > I'm accessing the method staticly. Google for "PHP class singleton" You will find several solutions. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting name of class from a parent
I'm not sure I'm quite clear on what you want, ... class base_class{ static function get_instance(){ static $oUtility = new utility_class(); return $oUtility; } } class utility_class { } $instance = utility_class::get_instance() ?> That should create an instance of utility_class the first time ::get_instance() is called, and just return it afterwards. I'm not positive it will work, the relationship between the two objects, with the parent instantiating it's own child, is quite complex. Hope this was of some help. Chris Rory Browne wrote: Hi I need a way to create an instance of a class, from a parent of that class. Lets say I have the following code: class base_class{ static function get_instance(){ // code I need goes here } } class utility_class { } $instance = utility_class::get_instance() ?> You may be wondering why I don't just " $instance = new utility_class " - the reason is that I want to only create one of these instances. I don't want any more than one instance of utility_class at any one time. I can't use get_class($this) either, because, there is no $this when I'm accessing the method staticly. Any suggestions? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] getting name of class from a parent
Hi I need a way to create an instance of a class, from a parent of that class. Lets say I have the following code: You may be wondering why I don't just " $instance = new utility_class " - the reason is that I want to only create one of these instances. I don't want any more than one instance of utility_class at any one time. I can't use get_class($this) either, because, there is no $this when I'm accessing the method staticly. Any suggestions? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php