Wayne,
Thank you for the reply. I hadn't considered the recursion problem. What I
was trying to do was create automatic accessors based on arrays in my
objects for has_a and has_many relationships. I put the code in the parent
class for ease of access to child classes and...duh...created deep
recursion.
Thanks,
I can see my way out now!
jg
"Wayne" <no*@here.com> wrote in message
news:66********************************@4ax.com...
On Wed, 23 Feb 2005 14:33:39 -0600, "jerrygarciuh"
<de*****@no.spam.nolaflash.com> wrote:
Is it possible to instantiate a child class within the constructor of its
parent?
I suppose it should work; the question is WHY would you want to do
this?!?
Class DBI extends DB {
function DBI() {
// explicit parent constructor call
$this->DB();
$class = get_class($this);
if ($class != '' && $class != 'dbi') { // only do this
for child classes
$obj = new $class; // BORK!!
What do you mean by "BORK!".. ;)
If a class subclasses DBI, and then called it's parent constructor,
this code would result in an endless loop. When the line "new $class"
is executed the constructor is called to instantiate the object and
this constructor is called again and so on until you run out of stack
space.
Any help with this syntax or is this a forbidden act?
The syntax is fine to me but whatever you are trying to accomplish
will not be accomplished by this. What is the purpose of all this?
Later,