Re: Re: Class::__construct() vs. $this->__construct()
| From: | Justin Patrin | Date: | Thu, 31 Mar 2005 01:12:46 +0000 |
| Subject: | Re: Re: Class::__construct() vs. $this->__construct() | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-37016@lists.php.net to get a copy of this message | ||
On Wed, 30 Mar 2005 19:39:15 -0500, Philippe Jausions
<Philippe.Jausions@11abacus.com> wrote:
> Joe Stump wrote:
> > What would the difference between:
> >
> > $this->__construct();
> >
> > and
> >
> > Class::__construct() be?
> >
> > I'm asking in regards to making my PHP4 classes "forward thinking" in
> > regards to an upgrade to PHP5. I'd like the code to nicely run in both
> > PHP4 and PHP5 and I've seen it done both ways. Is there a difference?
> >
> > class Foo extends Bar
> > {
> > function Foo()
> > {
> > Foo::__construct(); // Or should it be $this->__construct();
> > }
> >
> > function __construct()
> > {
> > parent::__construct();
> > }
> > }
> >
> > Thoughts?
> >
> > --Joe
> >
>
> Use $this->__construct() in the PHP 4 class constructor only. By Calling
> "Foo::__construct()" you're calling a static method, unrelated to the
> current instance.
>
> "parent::" is magic so the scope remains within the current instance.
>
As said earlier, this is incorrect. Both will do the same thing if Foo
is the name of the class. $this stays set wherever you go once you're
in a class method.
--
Justin Patrin