Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55509 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73073 invoked from network); 19 Sep 2011 00:37:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Sep 2011 00:37:59 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.170 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.160.170 mail-gy0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:58483] helo=mail-gy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/F5-28880-5EE867E4 for ; Sun, 18 Sep 2011 20:37:57 -0400 Received: by gyb11 with SMTP id 11so4455251gyb.29 for ; Sun, 18 Sep 2011 17:37:53 -0700 (PDT) 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=sWuA02/d4cZ3n+jvGrK8jzDQu170xksF0OlI7H8ooaM=; b=gpb5v4h2HEkZeQ7jPySB7q/S+597qMXQMAmq6pST4T473SY667UgFfV+a9RvamL26A Nu4pbFOZVjY9LxOLPMRo9oZMO1fsEia/VoZZKzL0CB1ltxZ0kutV58s/MVCYE+UZ31Kc 7F31v1tQUw/cJibJ54WmrFhBYpAKC2OuaWNrM= MIME-Version: 1.0 Received: by 10.236.177.72 with SMTP id c48mr10085905yhm.79.1316392673744; Sun, 18 Sep 2011 17:37:53 -0700 (PDT) Received: by 10.147.125.13 with HTTP; Sun, 18 Sep 2011 17:37:53 -0700 (PDT) In-Reply-To: References: <4E74E5A0.2030006@sugarcrm.com> <4E76320F.6010904@sugarcrm.com> <4E764137.9080507@sugarcrm.com> <4E7685DE.6010805@sugarcrm.com> Date: Mon, 19 Sep 2011 02:37:53 +0200 Message-ID: To: Pierre Joye Cc: Stas Malyshev , PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] __constructor parameter limitations. From: tyra3l@gmail.com (Ferenc Kovacs) On Mon, Sep 19, 2011 at 2:24 AM, Pierre Joye wrote: > On Mon, Sep 19, 2011 at 1:59 AM, Stas Malyshev w= rote: > >> foo() is compatible with foo($a, $b) - since anywhere you can call funct= ion >> declared as foo($a, $b) you can also successfully call one declared as >> foo(), it'd just ignore extra parameters - =C2=A0but it is not allowed (= I gave an >> example). It was bad when it was a useless E_STRICT, it is much worse wh= en >> it's a fatal error. > > It is not compatible as the two new parameters are not optional. > foo($a=3Dnull, $b=3D2) would be compatible. The only difference is that > (if we don't fail with the signature checks) warnings will be raised > for the missing arguments. But basically the problem is actually the > incompatible signature. Take this code: > > class foo{ > =C2=A0function __construct(){} > } > class bar extends foo{ > =C2=A0function__construct($a, $b){} > } > > if (is_a('bar', 'foo')) { > =C2=A0$a =3D new bar(); // warnings and maybe unexpected results due to t= he > lack of arguments > } > > to me (and to the OO concepts), they should fail at compile time to > avoid any kind of confusions or bad consequences/usage. But I can > understand that a fatal error could be seen as too extreme. > > >>> Are you saying that extending a class and making the constructor >>> incompatible with the extended class is a good thing to allow and to >>> do? If yes then I'd to strongly disagree with this idea as it allows >> >> I never said anything about constructor being "incompatible" with extend= ed >> class and it being good thing. I am saying rejecting compatible but not >> matching signatures - and I gave example of foo() vs foo($a, $b) - makes= no >> sense. And not even with E_STRICT - it's a fatal error now! > > Given that your example is not compatible, it is then fine to reject them= . > >>> And finally, the reason why abstract differs from the other areas is >>> that they are newer. It was decided not to break BC for the other >>> cases where we should have done the same. While Marcus wanted to do it >>> everywhere, with the same good reasons. >> >> I guess "all abstracts do that" is better than "abstracts except for cto= rs >> do that" but only marginally as both behaviors make little sense to me. >> Being restricted to abstracts limits the BC impact (as people could just >> remove the abstract keyword and thus avoid trouble relatively easily) bu= t in >> both cases it doesn't look too good. > > Where is the BC impact with abstract? It was always like that. It > happens to affect some newly written codes now but the behaviors is > not new. > >> I'm not sure if we should keep the new BC-breaking error in 5.4 for >> consistency sake (I'd felt much easier if we had discussed that before -= or >> we did and I just forgot?), but I seriously think we need to rework it i= n >> 5.5 and make all compatible signatures work without complaining. > > Which BC break fix? afair there is one bug fix Gustavo made which > creates bad side effects (about parent not being called or something > like that). Etienne was planning to work on that to find a better > solution. I don't have the bug # at hand but either Etienne or Gustavo > could explain it better, > the __construct was handled differently, as the other methods, so this was valid before 5.4: