Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54153 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2723 invoked from network); 23 Jul 2011 13:55:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jul 2011 13:55:41 -0000 Authentication-Results: pb1.pair.com smtp.mail=stefan.marr.de@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=stefan.marr.de@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) X-PHP-List-Original-Sender: stefan.marr.de@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:37103] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 37/70-32631-CD2DA2E4 for ; Sat, 23 Jul 2011 09:55:40 -0400 Received: by qyg14 with SMTP id 14so291843qyg.8 for ; Sat, 23 Jul 2011 06:55:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:reply-to:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=q21KFKjuXatNN79BNmFotfp0Voe3g2eQBNrQSEfyh8k=; b=bzNTBISlvRuj4h6+WiQEQSAdosabNiXSQcL9cErRRgDqcIKu6S0Eqa34cedJp9CkWQ aMyk8G0PV8PFijQQg+Av20G1/Xq7QCkuZbFPXFwn2zClplDRSeYD0QELLEZfMdTyesNp uYEvtBjy+2PrtusDS2PHKzOQBcT7a/r3SE11I= MIME-Version: 1.0 Received: by 10.229.105.153 with SMTP id t25mr920232qco.123.1311429336422; Sat, 23 Jul 2011 06:55:36 -0700 (PDT) Reply-To: php@stefan-marr.de Sender: stefan.marr.de@gmail.com Received: by 10.229.89.129 with HTTP; Sat, 23 Jul 2011 06:55:36 -0700 (PDT) In-Reply-To: <4E29949C.9020209@gmail.com> References: <4E29949C.9020209@gmail.com> Date: Sat, 23 Jul 2011 15:55:36 +0200 X-Google-Sender-Auth: kFTiazGr1CKJydk5FzZHenCeB5A Message-ID: To: Alex Howansky Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] 5.4a2 trait attribute name conflict resolution From: php@stefan-marr.de (Stefan Marr) Hi: On Fri, Jul 22, 2011 at 5:17 PM, Alex Howansky wr= ote: > > Hello folks, > > I've just grabbed 5.4a2 to play with traits. I've found some behaviour wh= ich > I'm not sure is a bug, an inconsistency, or a design decision. > > Consider a trait and a class that implements it but also overrides both a > trait method and a trait attribute: > > trait foo > { > =A0 =A0 public $zoo =3D 'foo::zoo'; > =A0 =A0 public function bar() > =A0 =A0 { > =A0 =A0 =A0 =A0 echo "in foo::bar\n"; > =A0 =A0 } > } > > class baz > { > =A0 =A0 use foo; > =A0 =A0 public $zoo =3D 'baz::zoo'; > =A0 =A0 public function bar() > =A0 =A0 { > =A0 =A0 =A0 =A0 echo "in baz::bar\n"; > =A0 =A0 } > } > > $obj =3D new baz(); > $obj->bar(); > echo $obj->zoo, "\n"; > > We get: > > in baz::bar > foo::zoo > > It seems this is not correct and that it should be: > > in baz::bar > baz::zoo After some more thought, my take on this is that those properties are not compatible, and we do the only simple thing possible and raise an error as soon as possible, because the trait might have changed to something that is not compatible with the class and the developer has to be made aware of that. While traits do not support state per se, we defined a minimal set of rules so that the use of properties which conflict in their semantics breaks as early as possible and noticeable to the developer. Please refer to https://wiki.php.net/rfc/horizontalreuse?&#handling_of_propertiesstate for the exact set of rules defined currently. These rules (rule 1) define that properties are considered incompatible if they differ in their initial value. Thus, the case you see here is, according to the rules defined in the RFC, a bug. And after looking at the implementation, it turns out that I just forgot to check one of the return values of the compare function. Thus, this is fixed as per http://svn.php.net/viewvc?view=3Drevision&revision=3D313632 Best regards Stefan