Re: Class::__construct() vs. $this->__construct()
| From: | Justin Patrin | Date: | Wed, 30 Mar 2005 22:12:22 +0000 |
| Subject: | Re: Class::__construct() vs. $this->__construct() | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-37001@lists.php.net to get a copy of this message | ||
On Wed, 30 Mar 2005 13:50:25 -0800, Joe Stump <joe@joestump.net> wrote:
> What would the difference between:
>
> $this->__construct();
Well, this one explicitly uses the one for this class. If you, say,
change the name of your class, this one will still work. Also, if you
removed the function from this class, this would automatically get the
parent's constructor.
>
> and
>
> Class::__construct() be?
This one specifies the class (namespace) but is the same as the one
above. The function is still called in the same way. The major
difference is that this one names the class it's calling the function
on. Changing the name of your class means having to change this call.
Also, if you remove __construct from this clas syou would have to
change it to use the parent's class name (or use parent:: instead).
>
> 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
>
> --
> Joseph C. Stump
> joe@joestump.net
> http://www.joestump.net
>
> --
> PEAR Development Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Justin Patrin