Re: constructors are callable as regular functions.

From: Date: Thu, 02 Jul 2009 14:58:44 +0000
Subject: Re: constructors are callable as regular functions.
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-44661@lists.php.net to get a copy of this message
Excerpts from troels knak-nielsen's message of Thu Jul 02 10:55:48 -0400 2009: > 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. Au contraire, you can employ this little trick: class A { private $a; private function __construct($a) { $this->a = a; } public function make($a) { return new A($a); } } But I agree; stab anyone who is doing $foo->__construct(). Except for testing. Testing is ok. Cheers, Edward

« previous php.internals (#44661) next »