Re: Class::__construct() vs. $this->__construct()
| From: | Greg Beaver | Date: | Wed, 30 Mar 2005 22:07:41 +0000 |
| Subject: | Re: Class::__construct() vs. $this->__construct() | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-36998@lists.php.net to get a copy of this message | ||
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 {If you use $this->__construct(), then you need not add a php4 constructor to child classes. This code shows the problem: <?php class Foo {function Foo() { Foo::__construct(); // Or should it be $this->__construct(); }function __construct() { parent::__construct(); }}
function Foo()
{
Foo::__construct()
}
function __construct()
{
echo 'Foo';
}
}
class Bar
{
function __construct()
{
parent::__construct();
echo 'Bar';
}
}
$a = new Bar;
?>
With this code, in PHP4, you'll see "Foo", and in PHP5, "FooBar"
Change Foo::__construct() to $this->__construct() and suddenly PHP4 matches PHP5.
Greg