Re: How to Get the Sub Classes of a Parent Class
| From: | Raymond Irving | Date: | Wed, 28 Oct 2009 00:25:42 +0000 |
| Subject: | Re: How to Get the Sub Classes of a Parent Class | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-299406@lists.php.net to get a copy of this message | ||
David,
I'm try to do something like what Martin Scotta did but I'm looking for a solution that
did not require me to loop through get_declared classes() to find a sub class.
__
Raymond Irving
________________________________
From: David Otton <phpmail@jawbone.freeserve.co.uk>
To: Raymond Irving <xwisdom@yahoo.com>
Cc: PHP-General List <php-general@lists.php.net>
Sent: Mon, October 26, 2009 8:33:02 PM
Subject: Re: [PHP] How to Get the Sub Classes of a Parent Class
2009/10/27 Raymond Irving <xwisdom@yahoo.com>:
>>> I want to automatically initialize a specific sub class when the php page
>>> is loaded.
>> You may be able solve this with a simple class_exists() (pseudo-code ahead):
>>
>> if(class_exists($var)) {
>> $class = new $var;
>> } else {
>> $class = new FourOhFour;
>> }
>> This works if you know the name of the class. What I'm looking for is a way
>> to get one of the sub classes and initialize it dynamically.
I'm confused. If you don't know the name of the child class, how are
you going to know which one to instantiate? Are you going to pick one
at random?
What you're trying to do can probably be accomplished, but I can't
shake the feeling we're trying to solve the wrong problem here.