Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67594 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27412 invoked from network); 31 May 2013 12:12:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 May 2013 12:12:04 -0000 Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.173 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 209.85.214.173 mail-ob0-f173.google.com Received: from [209.85.214.173] ([209.85.214.173:49039] helo=mail-ob0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A9/F4-02347-29398A15 for ; Fri, 31 May 2013 08:12:03 -0400 Received: by mail-ob0-f173.google.com with SMTP id wc20so2860351obb.18 for ; Fri, 31 May 2013 05:12:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=KTpUYumxU1ymiSfdlOrUavd8OmgRyVo+4SblRHLN6/0=; b=TDpn5ZTOyNIDsTAhp466WoBNxbgULnGQ1B9T58Itg6RG69Ze7N7FJlXUBWKf7qPb+H 5dtjDJuxYj0urzBBl52Pr7YIhH5ANAg+Oy2s32Vbz4RCHJSbbwtbzwmTuR5mLorx4lXT Pbq5HxOIdFs8O8TzXBy/fZPwRml6pTzQoGnykDYQOhGjjXhP4PH6drfLAjAed6vZmwYs EIPVYSqgS6qe+SylknPfIrbcbVNrDIoMVNj9w+MsvO1nHr+hlNb/4A6yneXfKwKcD6Zn pmL4DZbeofiR3JSn2OGum3dGbA8fKFYOguasrshnG+oXtaSPXn2vHjVlMqPx8RJsOZRb RVhw== X-Received: by 10.182.241.194 with SMTP id wk2mr5777303obc.77.1370002320140; Fri, 31 May 2013 05:12:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.76.160.67 with HTTP; Fri, 31 May 2013 05:11:40 -0700 (PDT) In-Reply-To: References: <6b642a96e673c29dbaf2f239be15f7f6.squirrel@www.l-i-e.com> Date: Fri, 31 May 2013 14:11:40 +0200 Message-ID: To: Anthony Ferrara Cc: Richard Lynch , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e01536b4ea23b6704de028555 Subject: Re: [PHP-DEV] Cannot call constructor From: linepogl@gmail.com (Lazare Inepologlou) --089e01536b4ea23b6704de028555 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2013/5/30 Anthony Ferrara > Richard et al, > > > On Thu, May 23, 2013 at 5:24 PM, Richard Lynch wrote: > > > Consider this common scenario: > > > > I use some OOP library, that is a "black box" and I like it that way. > > > > As part of the integration, I need to extend one of the library's > > classes: > > > > The problem with this entire thread (I've been thinking about this for a > while) is that it's setup from the very beginning with a failed assertion= . > You want to treat a library as a black box. Great! However, you also want > to extend one of the library's classes. That's not ok. Because you cannot > ever treat inheritance as a black box. It goes against just about every > principle out there. And it's provably not possible to do. > > I cannot agree with you here. This is exactly why the "protected" keyword exists: to provide a black-box interface for class usage through inheritance. Yes, this is not automatic and, yes it needs designing, but it is certainly not against the principles. If it were, we should remove the "protected" keyword as well. > Treating it like a black box will cause LSP violations (which PHP is so > keen on enforcing). Why? Because if you treat the parent as a black-box, > you can't guarantee that the pre-conditions, post-conditions > and invariants are not enforced (which LSP requires). So without looking = at > the parent, you can't have a child that adheres to LSP. > > But let's get less "rule" and more practical. Imagine the parent has no > constructor. So you, in future hindsight, decide to do this: > > if (method_exists(get_parent_class(), '__construct')) { > call_user_func_array(array(get_parent_class(), '__construct'), > func_get_args()); > } > > Now, what happens if the parent constructor now takes a parameter by > reference? The reference will be lost. The conceptual implementation is n= ow > gone. Not to mention that the parameters may (and will likely) be differe= nt > from what you were expecting. > > So basically, we can't ever develop completely in a black box. So if the > parent has a constructor, we need to call it (or not). But the point is, > it's never a conditional in the code. It requires you to look at, and mak= e > a decision. > > So that brings us to the case when you override a class that doesn't have= a > constructor, which then gets one later on down the road. This is really > just the same as before and boils down to: 1. Test your code, as a test > should catch that. 2. Don't blindly update and expect code to work. 3. Ev= en > if you did have a conditional, you're likely to get the arguments wrong (= or > worse)... > > So realistically, while I can see the appeal to having the ability to > always call parent::__construct(), I think it's actually a red-herring to > the actual problem. And it's not really necessary in the first place. In > fact, using it is likely to be a source of *more* bugs, as the object sti= ll > won't be initialized properly (but you think it is)... > > My $0.02 at least, > > Anthony > Lazare INEPOLOGLOU Ing=C3=A9nieur Logiciel --089e01536b4ea23b6704de028555--