On Thu, Jul 2, 2009 at 4:47 PM, Edward Z. Yang<ezy...@mit.edu> wrote: > Excerpts from troels knak-nielsen's message of Thu Jul 02 10:14:18 -0400 2009: >> I would have expected the second call to __construct() to yield an error. > > Why should it? Especially since this is idiomatic code: > > class A { > public function __construct($a) { > $this->a = $a; > } > } > > class B extends A { > public function __construct($a, $b) { > $this->b = $b; > parent::__construct($a); > } > }
In that example, the object instance is not initialised when parent::__construct() is called. > __construct doesn't do anything like allocate memory. It just happens > to get called when we do "new B(1, 2)" I understand that. It's not a technical issue - It's more a matter of language semantics. Constructors are used for initializing state on an object. Basically, this behaviour makes it impossible to implement immutable objects in php. It's not a huge deal - I don't remember ever seen __construct() called directly. -- troels -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php