Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56567 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86340 invoked from network); 24 Nov 2011 10:48:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Nov 2011 10:48:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.49 as permitted sender) X-PHP-List-Original-Sender: rquadling@gmail.com X-Host-Fingerprint: 209.85.216.49 mail-qw0-f49.google.com Received: from [209.85.216.49] ([209.85.216.49:40267] helo=mail-qw0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 28/E5-46656-A012ECE4 for ; Thu, 24 Nov 2011 05:48:42 -0500 Received: by qabj40 with SMTP id j40so26416qab.8 for ; Thu, 24 Nov 2011 02:48:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=acboNFtFpWaaUdmDo1mv8AU6k5IP9PkfSYImMLmyqSo=; b=sdxfuAn+BhF46jex4/Umka8d1/Euuv1zqC8aMLDIEs5Gq9RWiMl27GYK2U1+95avPX FpZUXH+4KgY2UuKLSIz4U5Al9aC/642XUMqDHrSUl8ss1ViEcFhIKbW2clyJOrUZS/45 AkQy7x7p9lfovawYhZ0G6Z5nc3a/zNO9ngEWw= Received: by 10.182.41.100 with SMTP id e4mr9344208obl.63.1322131719155; Thu, 24 Nov 2011 02:48:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.42.226 with HTTP; Thu, 24 Nov 2011 02:48:18 -0800 (PST) Reply-To: RQuadling@GMail.com In-Reply-To: References: <4EC578C9.4000408@ralphschindler.com> <4ECD3A9E.7090105@ralphschindler.com> Date: Thu, 24 Nov 2011 10:48:18 +0000 Message-ID: To: Anthony Ferrara Cc: Ralph Schindler , Pierre Joye , Derick Rethans , internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Changes to constructor signature checks From: rquadling@gmail.com (Richard Quadling) On 23 November 2011 18:37, Anthony Ferrara wrote: > Ralph: > > From where I'm sitting, I can see a few sane alternatives (there may > be more, but here are the options I can see): > > Option 1. =C2=A0Remove signature checking from constructors all together. > (I don't care for this, but whatever). =C2=A0Additionally, since it's not > enforced, perhaps an E_DEPRECATED or E_STRICT error should be raised > on definition, as it is superfluous... > > Option 2. =C2=A0Fix grandchild signature checking to be inline for how > signatures work with other methods. > > Personally, I think option 2 is the better one. =C2=A0I see it being odd > and inconsistent that all methods work one way, and constructors work > differently. =C2=A0But that's just my feeling (and I know others disagree > there). > > And please don't reduce the error level of a signature change (as it > would introduce even more inconsistency)... > > Just my $0.02... > > Anthony > > On Wed, Nov 23, 2011 at 1:25 PM, Ralph Schindler > wrote: >> Internals: >> >> Time to summarize. >> >> It is clear to me that internals is divided on this issue. =C2=A0I don't= think >> it's a large enough issue to drag on, even when I disagree with it - bot= h >> theoretically and in practice. >> >> For most OO developer, putting ctors as an abstract or in an interface w= ould >> not happen anyway, so this does not affect them. >> >> ** The current change represents a minor break in BC, that should be not= ed >> in the manual. ** >> >> Also, a decision needs to be made on what to do with grandchildren. =C2= =A0As I >> mentioned, the following produces no E_FATAL and no warnings: >> >> =C2=A0abstract class A { =C2=A0abstract public function __construct($a, = $b); } >> =C2=A0class B extends A { public function __construct($a, $b) {} } >> =C2=A0class C extends B { public function __construct(ArrayObject $d) {} >> >> While this is correct behavior to me (ability for concrete to use its ow= n >> ctor), using the *current logic* strict signature checking enforced from= an >> abstract, then the above is also wrong. >> >> ** Can we decide what to do with that situation? ** >> >> On 11/18/11 5:05 AM, Pierre Joye wrote: >>> >>> I strongly disagree, this encourages bad practices. We could however >>> reduce the error level to warning. >> >> I think this is a sufficient compromise- I don't see anything E_FATAL ab= out >> a signature change in ctors (I actually see nothing wrong with it, but i= t's >> clear the community is divided there). >> >> ** Can we make that change? ** >> >> >> Thanks, >> -ralph What is the normal way for userland developers to learn about constructors? Do they know about LSP? If they do, does it apply to constructors? A comment on StackOverflow [1] "At its heart LSP is about interfaces and contracts as well as how to decided when to extend a class vs. use another strategy such as composition to achieve your goal." I am self taught. It was always my understanding that the constructor was special in that it is, essentially, a magic method that can only respond to the new keyword. Being able to call the constructor directly, ..., that does feel a little odd as I can't actually construct a new instance that way. Using an interface to enforce the sig is fine. That's the exact nature of an interface, to enforce the contract by design and if the StackOverflow comment is accurate, then my understanding of interfaces is fine with regard to LSP. An abstract class, by its very nature is not formed. It isn't a contract. It is an idea and the concrete doesn't need to fit perfectly. OK. There is some things that are fixed, method signatures most accept the parameters defined in the subclass but can add more (as I understand things). But is the signature of the constructor in an abstract class to be enforced? I feel that it shouldn't be. It is a special method. WikiPedia [2] has an article on Constructor Overloading. It says "Constructors, used to create instances of an object, may also be overloaded in some object oriented programming languages.". OK, so WikiPedia may have a different opinion tomorrow. Whilst we don't support overloading in the same way (I think we can simulate it with __call() easily enough with ReflectionParameter being my friend here maybe). We, DO, provide the tools to allow overloading and non LSP coding practises. Is it a great leap to also allow the same flexibility with constructors? Regards, Richard Quadling. [1] http://stackoverflow.com/questions/56860/what-is-the-liskov-substitutio= n-principle [2] http://en.wikipedia.org/wiki/Constructor_overloading#Constructor_overlo= ading --=20 Richard Quadling Twitter : EE : Zend : PHPDoc : Fantasy Shopper @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea=C2=A0: fan.sh/6/370