Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54131 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47876 invoked from network); 22 Jul 2011 15:51:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jul 2011 15:51:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@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: rquadling@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:64414] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9C/35-15078-A6C992E4 for ; Fri, 22 Jul 2011 11:51:07 -0400 Received: by qyg14 with SMTP id 14so4315641qyg.8 for ; Fri, 22 Jul 2011 08:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=2iUdY+HstTLK8SHAD+Sz3+cBu/r/CSOeFn+iyMgia4c=; b=q86jpcnFABONi/YHpOJvHrYMvNmqjXwsoWBVBsMfFpsha9AMvUSkB6f2AHQ1rpE97i NqfDUYikodCOVzk5Ni7oALy9O6mE9XCtJRYhELC2QERW+RFYyEzWGWdQhmpKpPVPjq2f H5LtDr+duW8Lr0RFZzUMZ+UyL7QvWJJEPUXVk= Received: by 10.229.227.136 with SMTP id ja8mr1389713qcb.75.1311349864298; Fri, 22 Jul 2011 08:51:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.87.70 with HTTP; Fri, 22 Jul 2011 08:40:51 -0700 (PDT) Reply-To: RQuadling@GMail.com In-Reply-To: <4E29949C.9020209@gmail.com> References: <4E29949C.9020209@gmail.com> Date: Fri, 22 Jul 2011 16:40:51 +0100 Message-ID: To: Alex Howansky Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] 5.4a2 trait attribute name conflict resolution From: rquadling@gmail.com (Richard Quadling) On 22 July 2011 16:17, Alex Howansky wrote: > > 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 > { > =C2=A0 =C2=A0 public $zoo =3D 'foo::zoo'; > =C2=A0 =C2=A0 public function bar() > =C2=A0 =C2=A0 { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 echo "in foo::bar\n"; > =C2=A0 =C2=A0 } > } > > class baz > { > =C2=A0 =C2=A0 use foo; > =C2=A0 =C2=A0 public $zoo =3D 'baz::zoo'; > =C2=A0 =C2=A0 public function bar() > =C2=A0 =C2=A0 { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 echo "in baz::bar\n"; > =C2=A0 =C2=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 > > The traits RFC pretty clearly states that if a class method conflicts wit= h a > trait method then the trait method will be ignored, which is what's > happening, but it says nothing about what happens to attributes in that s= ame > condition. Is this a bug? > > Thanks, > > -- > Alex Howansky > > In my limited understanding, a trait is sort of composited at compile time (ish). As properties are dynamic (ish), they will overwrite. Just like an inherited class will overwrite public properties in their parent class. --=20 Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea