Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56373 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59924 invoked from network); 17 Nov 2011 21:12:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2011 21:12:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=ralph@ralphschindler.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ralph@ralphschindler.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain ralphschindler.com from 209.85.213.170 cause and error) X-PHP-List-Original-Sender: ralph@ralphschindler.com X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:41338] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3B/85-30628-EC875CE4 for ; Thu, 17 Nov 2011 16:12:46 -0500 Received: by yenl2 with SMTP id l2so1866061yen.29 for ; Thu, 17 Nov 2011 13:12:43 -0800 (PST) Received: by 10.236.191.5 with SMTP id f5mr312401yhn.122.1321564363739; Thu, 17 Nov 2011 13:12:43 -0800 (PST) Received: from ralph-macbook.local (wsip-98-173-234-93.no.no.cox.net. [98.173.234.93]) by mx.google.com with ESMTPS id j25sm7761118yhm.12.2011.11.17.13.12.42 (version=SSLv3 cipher=OTHER); Thu, 17 Nov 2011 13:12:43 -0800 (PST) Message-ID: <4EC578C9.4000408@ralphschindler.com> Date: Thu, 17 Nov 2011 15:12:41 -0600 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.9) Gecko/20061207 Thunderbird/1.5.0.9 Mnenhy/0.7.4.666 MIME-Version: 1.0 To: internals Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Changes to constructor signature checks From: ralph@ralphschindler.com (Ralph Schindler) Hey All, Concerning RC1, __construct() and https://wiki.php.net/rfc/prototype_checks I think we need to round out this discussion on the __construct() signature checking in 5.4. The current behavior (RC1) feels very wrong with respect to PHP's class based, single inheritance, multiple interface, no method overloading, allowed method-overriding nature. Constructors themselves, specifically in PHP, are not explicitly statically marked, but are "special" (even though they are part of the instance API, and are callable- we'll consider this an implementation detail). In general, constructor signatures have never been (and rightfully so) governed by the LSP. Why? For a few reasons: 1) before calling new(), you actually don't have a subtype (yet)- the subtype is a *product* of new() 2) when you call new(), you know the exact subtype you're dealing with. 3) only subtypes who implement or override __construct() can know how to prepare a stateful subtype. In 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 when a subtype has overridden __construct(); 4) 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 not 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. (Neither c# or java allow this- of course they do have the ability to overload methods in classes for the record. In fact, static methods are not allowed either.) That said, we really should consider removing this limitation from constructor signature checking. Not only is it a BC break, it doesn't make sense in the context of PHP. Thoughts? Thanks, Ralph Schindler