Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44660 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66348 invoked from network); 2 Jul 2009 14:55:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jul 2009 14:55:52 -0000 Authentication-Results: pb1.pair.com header.from=troelskn@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=troelskn@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.224 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: troelskn@gmail.com X-Host-Fingerprint: 209.85.220.224 mail-fx0-f224.google.com Received: from [209.85.220.224] ([209.85.220.224:59959] helo=mail-fx0-f224.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D4/0B-16153-77ACC4A4 for ; Thu, 02 Jul 2009 10:55:52 -0400 Received: by fxm24 with SMTP id 24so1718797fxm.23 for ; Thu, 02 Jul 2009 07:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=1shXJal8lipPlUGwTONRJbuF7uH4406EnMeAI3yUeXU=; b=wG6X0nAKFDhGpHpjrYcA7eXQccwyXlwSfE/hMQYWkoG70MbtZ2EknmbwfPQPhFo1Ma MqMc042zx9j9OSq2gfOF0bQ87kqDtRdjLvv64NjvdLYoXeAMrA9Wy1M3pWgbrLSIDU8l Gm2qS3GA9bD2XXgmXb49/LOcGhZb6FYvpLHuA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=ba4ehJQr9Vy9ujer/JiBqFEgBCxVy3VmwjubLNkXfleBiAAaQMKGPwfFmUu+ogBjSO v9aabhYif31FqjRF+gRggtp0U0N8HxAbq90Zb1JhB8nMEyA1JaxAb0Ghob1i7UjM3Lid 2C57sJll4X2ATQ9OURoy2M8B9BVeee7K6y6y4= MIME-Version: 1.0 Received: by 10.223.120.197 with SMTP id e5mr162139far.25.1246546549194; Thu, 02 Jul 2009 07:55:49 -0700 (PDT) In-Reply-To: <1246545959-sup-2910@javelin> References: <98b8086f0907020714m6c67fce3jab4d13429b3cd2a4@mail.gmail.com> <1246545959-sup-2910@javelin> Date: Thu, 2 Jul 2009 16:55:48 +0200 Message-ID: <98b8086f0907020755k1c29930n8a4cef38dbb61291@mail.gmail.com> To: internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] constructors are callable as regular functions. From: troelskn@gmail.com (troels knak-nielsen) 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 { > =A0public function __construct($a) { > =A0 =A0$this->a =3D $a; > =A0} > } > > class B extends A { > =A0public function __construct($a, $b) { > =A0 =A0$this->b =3D $b; > =A0 =A0parent::__construct($a); > =A0} > } 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