Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44662 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69438 invoked from network); 2 Jul 2009 15:05:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jul 2009 15:05:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=greg@chiaraquartet.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=greg@chiaraquartet.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain chiaraquartet.net from 209.85.216.178 cause and error) X-PHP-List-Original-Sender: greg@chiaraquartet.net X-Host-Fingerprint: 209.85.216.178 mail-px0-f178.google.com Received: from [209.85.216.178] ([209.85.216.178:35865] helo=mail-px0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A5/00-03575-EBCCC4A4 for ; Thu, 02 Jul 2009 11:05:35 -0400 Received: by pxi8 with SMTP id 8so2051197pxi.29 for ; Thu, 02 Jul 2009 08:05:32 -0700 (PDT) Received: by 10.114.103.1 with SMTP id a1mr167606wac.218.1246547132072; Thu, 02 Jul 2009 08:05:32 -0700 (PDT) Received: from monster.local ([76.84.30.125]) by mx.google.com with ESMTPS id b8sm11031744rvf.7.2009.07.02.08.05.30 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 02 Jul 2009 08:05:31 -0700 (PDT) Message-ID: <4A4CCCB8.4090409@chiaraquartet.net> Date: Thu, 02 Jul 2009 10:05:28 -0500 User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070807) MIME-Version: 1.0 To: troels knak-nielsen CC: internals References: <98b8086f0907020714m6c67fce3jab4d13429b3cd2a4@mail.gmail.com> <1246545959-sup-2910@javelin> <98b8086f0907020755k1c29930n8a4cef38dbb61291@mail.gmail.com> In-Reply-To: <98b8086f0907020755k1c29930n8a4cef38dbb61291@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] constructors are callable as regular functions. From: greg@chiaraquartet.net (Greg Beaver) troels knak-nielsen wrote: > On Thu, Jul 2, 2009 at 4:47 PM, Edward Z. Yang 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 Hi, __construct can be private or protected, it just requires implementing a factory() or singleton() method to retrieve the immutable object. Greg