Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56407 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28213 invoked from network); 18 Nov 2011 18:40:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Nov 2011 18:40:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vw0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:47970] helo=mail-vw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/45-06569-C96A6CE4 for ; Fri, 18 Nov 2011 13:40:28 -0500 Received: by vbbfo1 with SMTP id fo1so458539vbb.29 for ; Fri, 18 Nov 2011 10:40:25 -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; bh=dMC0D+cWYTwKFFae+SQdBrkFZlaI0n+IoRWMExHjNlg=; b=dwC+jbFbOM3bKzL0bPmHj0oJ8rvqxfiNFSwoCtQaJQ8d3CyBi8bc/QA3UFZix3hwvN 4hrRFT/aoVwR9Xb04AV6criCzeHHlFDsJZMmvx8Vs9yTXdZIOFR5lcjFljWTla7PBcvF q6o+2Z4h3X6AvSVJVA2E1RfqM9pXMCLOnfWMk= MIME-Version: 1.0 Received: by 10.224.18.69 with SMTP id v5mr1984321qaa.31.1321641625188; Fri, 18 Nov 2011 10:40:25 -0800 (PST) Received: by 10.229.5.84 with HTTP; Fri, 18 Nov 2011 10:40:25 -0800 (PST) In-Reply-To: <4EC69872.6060300@ralphschindler.com> References: <4EC578C9.4000408@ralphschindler.com> <4EC69872.6060300@ralphschindler.com> Date: Fri, 18 Nov 2011 13:40:25 -0500 Message-ID: To: Ralph Schindler Cc: Pierre Joye , internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Changes to constructor signature checks From: ircmaxell@gmail.com (Anthony Ferrara) Comments Inline > 1) What we know and have been told is that PHP's signature > checking is governed by Liskov Substitution Principle. There are > many references to this in the list. Except that signature checking is not needed for LSP to function. You can write all of your code using duck typing without interfaces and abide by LSP 100%. In fact, you can do things like override a function with a signature of foo($bar, $baz) with one of foo(), and STILL have it be LSP compliant due to the dynamic ways PHP handles arguments. So LSP may be a motivator, but ti's not the reason. What could be a reason is to enable Design-By-Contract style development where the interface is the defined contract. Now since PHP doesn't support dynamic introspection of the method at run-time, the signature is the only way of determining if the method abides by the contract. > 2) "Abstract Constructors" do not exist in any other language, for all > intents and purposes, it's something we've invented: True, however in most other language constructors are not actual methods, but a pseudo method on the object that can't be called explicitly aside form `new` (obviously not true for all, but most of the big ones). Additionally, PHP is quite different from a fair bit of other languages in that you can do things like `new $class()`. Java and C# don't allow this. So to them, it's not an LSP violation or even necessary to have it abstract since you **know** the subtype your instantiating. However, in PHP that's not true. You can do variable-class-names. So that eliminates the assertion that you **know** the subtype your instantiating. You don't, and you can't. But you can check the interface on the class name in the variable (which is what I did in that library I posted before). So by specifying the constructor as abstract/interface is one way of adding safety when you accept a class name and do dynamic instantiation... > http://www.google.com/search?&q=%22abstract+constructor%22 > > That's fine, so now the question is, how does this thing we've invented play > in with our current implementation of a class based object model and how > does it meet developer preexisting expectations? There are two ways to see it. Either constructors are really just a method that's called by the engine, or they are not a method and are special "blocks" which are not callable in userland. However, since I can legally call `$obj->__construct()`, I think it's pretty safe to say that it's considered a real method in PHP. And real methods are specifiable in abstract/interfaces. So really we didn't invent anything at all. The "invention" is that the constructor is a method (with all the caveats that apply)... > 3) In places that have no formal expectation and understanding in other > programming languages, we've OFTEN favored *looseness over strictness* > > Even you Pierre, once promoted "looseness" > http://news.php.net/php.internals/25089 (Pierre) Well, looseness over strictness unless strictness is specified. Look at the class based type hints. That's strict. Interfaces and signature checking are absolutely strict. Considering that the use is optional, and the construct that's using it is normally associated with strictness that it's ok that the constructor check is strict... Again, I'm not arguing the design decision of putting a constructor in an interface. I'm talking about what would be expected if you did, or more specifically if you're allowed to...