yes, you were right it works (when you said it works i tested your code out
and it definetly works). but this made me more confused than i was before.
i commented in the lines in my code that earlier didn't work (replaced them
sometime with class names hard coded solution) and it still did _not_ work.
ok, made copies of files in action and started to strip them down.

First, my stripped down code that works:
<?
class a {
    function make($params) {
    }
}
class b extends a {
    function make() {
        echo "WORKS OK";
    }
}
class c extends b {
    function make($params) {
        parent::make();
    }
}
class d extends c {
    function make($params) {
        parent::make($params);
    }
}

$d = new d();
$d->make("whatever");
?>

now, when i remove the definition of class 'a' to another file and include
the file like this:

file1.php:

<?
class a {
    function make($params) {
    }
}
?>

file2.php:

<?
include "./file1.php"; // or require - no difference

class b extends a {
  function make() {
   echo "WORKS OK";
  }
}

class c extends b {
 function make($params) { // this gets called forever !!!! and generating
warnings
    parent::make();
  }
}

class d extends c {
 function make($params) {
   parent::make($params);
  }
}

$d = new d();
$d->make("whatever");
?>

then i get message 'Warning: Missing argument 1 for make()' ... the code is
same ... but working differently.at least with my php 4.0.5. so i think this
is a bug.

that include in our system is neccessary so to the point it works correctly,
i have to hardcode class names.

and thank you scott pointing me out (and getting me confused :) ).

lenar.

"scott [gts]"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> it looks like your solution *is* elegant... i tried
> out your code, becuase i was astonished that such a
> simple thing allegedly wasn't working... and it
> did work.
>
> below is the exact code i had in my text editor,
> and it executed perfectly.
> when i called $c->make(), it printed "A:: MAKE".
>
> ..am i misunderstanding your problem?
>
>
> <?
>
> class a {
>     function make() {
>         // some code
>         print "A:: MAKE";
>     }
> }
>
> class b extends a {
>     function make() {
>         // some code
>         parent::make();
>     }
> }
>
> class c extends b {
>     function make() {
>         // some code
>         parent::make();
>     }
> }
>
>
>
> $c = new c();
> $c->make();
>
> ?>
>
>
> > -----Original Message-----
> > From: Lenar Lõhmus [mailto:[EMAIL PROTECTED]]
> > Sent: 20 June 2001 09:01
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] parent and grandparent member functions
> >
> >
> > Hello,
> >
> > I hit a wall. No offense, but this OO stuff in PHP is somehat weird, but
> > skip to the problem.
> > I have for example three classes:
> >
> > class a {
> >     function make() {
> >         // some code
> >     }
> > }
> >
> > class b extends a {
> >     function make() {
> >         // some code
> >         parent::make();
> >     }
> > }
> >
> > class c extends b {
> >     function make() {
> >         // some code
> >         parent::make();
> >     }
> > }
> >
> > now the class 'c' is instantiated and the member function 'make' is
called.
> > All works up to the point where 'b'::make calls parent::make().
> > It seems to call itself :(. I can understand this is logical behaviour
since
> > it's still an instance of class c,
> > so parent:: is still b::, but how should I call that grandparent's
make()???
> > This doesn't seem like a good OOP.
> > For example delphi's 'inherited' works relative to the class it's used
in
> > and it is way more useful than php's way.
> >
> > is there any elegant soultion(s) to my problem?
> >
> > Lenar Lõhmus
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to