Re: Re: Class::__construct() vs. $this->__construct()

From: Date: Fri, 01 Apr 2005 16:32:27 +0000
Subject: Re: Re: Class::__construct() vs. $this->__construct()
References: 1 2 3 4 5 6  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-37047@lists.php.net to get a copy of this message
Stephan Schmidt wrote:
Hi, Joe Stump schrieb:
I only asked because I saw XML_Parser was calling XML_Parser::__construct() from function XML_Parser(). I though $this->__construct() would be safer. A bug possibly?
Imagine this class: MyParser extends XML_Parser {
     function MyParser()
     {
       $this->__construct();
     }
     function __construct()
     {
       ....
       parent::XML_Parser();
     }
} If you create a new instance and XML_Parser would be using $this->__construct(), it would call MyParser::__construct() instead of XML_Parser::__construct(). That's why XML_Parser is specifying the class name. Otherwise inheritance is no longer possible or will totally break scripts. Stephan
That is why you shouldn't mix constructor styles. If implementing __construct() for PHP4 you need to modify your whole hierarchy. You can't hop from PHP4 style constructor to PHP5 then back on PHP4. Once you do a $this->__construct() you shouldn't make calls to PHP4 constructors. If you do behavior is unexpected as you pointed out. -Philippe

« previous php.pear.dev (#37047) next »