Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56388 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44546 invoked from network); 18 Nov 2011 09:29:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Nov 2011 09:29:22 -0000 Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.42 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.213.42 mail-yw0-f42.google.com Received: from [209.85.213.42] ([209.85.213.42:62790] helo=mail-yw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0F/36-06569-07526CE4 for ; Fri, 18 Nov 2011 04:29:21 -0500 Received: by ywm19 with SMTP id 19so2540378ywm.29 for ; Fri, 18 Nov 2011 01:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=xqtkA4oxShb9IvQj0arwwzYsdPKoPbWHfW6qcktUhX4=; b=UHYXh4WlADKbYjqdxSxTSohzicpXx5UVh1KcewOJSblrcgjvFuWWPNpnIj2mAAZ4np lqsz/YccNsaoFl+5zCzAGi5BXqRXnEoqFWvSADshRq9ZEKQ5yTzvoheeP+0H5kt/vzjU zXMHn8jejtSgaxJHGSWZjePvLMn6HCffXE0oA= MIME-Version: 1.0 Received: by 10.100.208.8 with SMTP id f8mr334714ang.11.1321608558157; Fri, 18 Nov 2011 01:29:18 -0800 (PST) Received: by 10.147.99.18 with HTTP; Fri, 18 Nov 2011 01:29:18 -0800 (PST) In-Reply-To: <4EC578C9.4000408@ralphschindler.com> References: <4EC578C9.4000408@ralphschindler.com> Date: Fri, 18 Nov 2011 10:29:18 +0100 Message-ID: To: Ralph Schindler Cc: internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Changes to constructor signature checks From: pierre.php@gmail.com (Pierre Joye) hi, On Thu, Nov 17, 2011 at 10:12 PM, Ralph Schindler wrote: > Hey All, > > Concerning RC1, __construct() and https://wiki.php.net/rfc/prototype_chec= ks > > I think we need to round out this discussion on the __construct() signatu= re > checking in 5.4. =A0The current behavior (RC1) feels very wrong with resp= ect > to PHP's class based, single inheritance, multiple interface, no method > overloading, allowed method-overriding nature. > > Constructors themselves, specifically in PHP, are not explicitly statical= ly > marked, but are "special" (even though they are part of the instance API, > and are callable- we'll consider this an implementation detail). =A0In > general, constructor signatures have never been (and rightfully so) gover= ned > by the LSP. =A0Why? For a few reasons: > > =A01) before calling new(), you actually don't have a subtype (yet)- the > subtype is a *product* of new() > > =A02) when you call new(), you know the exact subtype you're dealing with= . > > =A03) only subtypes who implement or override __construct() can know how = to > prepare a stateful subtype. =A0In other words, parents can't know how to > create subtypes who implement __construct() and subtypes shouldn't be > concerned with the implementation details of how a parent creates types w= hen > a subtype has overridden __construct(); > > =A04) LSP deals with behaviors and expectations of types (read: objects), > since the constructor is generally considered "static" in nature, a form = of > factory specific to the type its defined within, and since in PHP you can= 't > do (SomeClass instanceof SomeType) and since (is_a('SomeClass', 'SomeType= ') > doesn't make much sense in the context of classes), the constructor is no= t > subject to instance "behavior" rules. > > In general, developers shouldn't be putting abstract constructors inside = an > abstract class nor should they be putting constructors inside interfaces- > this is a well accepted bad practice. =A0(Neither c# or java allow this- = of > course they do have the ability to overload methods in classes for the > record. =A0In fact, static methods are not allowed either.) > > That said, we really should consider removing this limitation from > constructor signature checking. =A0Not only is it a BC break, it doesn't = make > sense in the context of PHP.