Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61919 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75853 invoked from network); 1 Aug 2012 12:57:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Aug 2012 12:57:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=sv_forums@fmethod.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sv_forums@fmethod.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fmethod.com from 74.125.83.42 cause and error) X-PHP-List-Original-Sender: sv_forums@fmethod.com X-Host-Fingerprint: 74.125.83.42 mail-ee0-f42.google.com Received: from [74.125.83.42] ([74.125.83.42:38412] helo=mail-ee0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3C/77-32875-8A729105 for ; Wed, 01 Aug 2012 08:57:13 -0400 Received: by eekb15 with SMTP id b15so1821800eek.29 for ; Wed, 01 Aug 2012 05:57:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:from:to:cc:references:subject:date:mime-version :content-type:content-transfer-encoding:x-priority:x-msmail-priority :x-mailer:x-mimeole:x-gm-message-state; bh=SH3qr/MXn4SReBwUAn30qWQ6/PeA8GgEC4YZh9VRPE0=; b=ZfvcmI8t47s+bLzBMkAPAZhcvoarP5FpiPe0DgTJIZiejgjScMtF72Ful4RLKqQzgQ U9wCpgAaKTddfEmDzqXYD1Bl2Zq4yAajyrolPmK5ET/T+KeOO1Jt7RSTLmyGvzEKOV+n rNsWrkfj8QTjqLI1kUwqIG0EOh5bCDr8qowPHSlnbemXVDnz48Hdi9dpO2yrRANPK+b+ EpGuLrJ4fFV6IhlaI4NcKEFjt/La/hlAYDzywfZzOHp6Aql0+D3yIAAFG8PQh3ls0+uo 0QD7fIBr3jIjU4Z9KW8KqU78Ql9dW/WHqlgwfDV5DuY8/et+cNEWmhndeTwCRpsKmeKg OMvA== Received: by 10.14.221.132 with SMTP id r4mr22289775eep.41.1343825829302; Wed, 01 Aug 2012 05:57:09 -0700 (PDT) Received: from pc (79-100-60-213.btc-net.bg. [79.100.60.213]) by mx.google.com with ESMTPS id u48sm8713573eep.7.2012.08.01.05.57.07 (version=SSLv3 cipher=OTHER); Wed, 01 Aug 2012 05:57:08 -0700 (PDT) Message-ID: To: "Stefan Marr" Cc: References: <232501B15F7F4B3197123F219370E36D@pc> <2125641B4C7D4D6E8616F86C9C5563D2@pc> <5D98E000-D40D-43EC-9C94-D5B00331C82E@stefan-marr.de> Date: Wed, 1 Aug 2012 15:56:59 +0300 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Gm-Message-State: ALoCoQl/ujQKTPZMaBrEvemoNLsgPIOlKQf9LUAPHkGGaYk5OQg0Gw/yZkE3iam7GgsxXF68ZV4C Subject: Re: [PHP-DEV] Traits behavior still up in the air in 5.4 From: sv_forums@fmethod.com ("Stan Vass") > From that follows that traits override the super class's methods. > And, conflict resolution is only done between traits, not between a class > and its traits. > The class body is a definite thing. Why would you purposefully add > something to a class body that conflicts with a trait? > The class needs to know exactly what the traits are doing. There is no > black-box reuse. But that's precisely my point. No class would *purposefully* add something to conflict with a trait. Then by your own description the only case is *accidentally* adding something to conflict with it. In such a case why on Earth is it allowed without a fatal error? >The use case for overriding is typically that you got a conflict that you >need to resolve by making a call to both conflicting methods. > Consider two traits that happen to provide a log() function, and in the > resulting class you need to call both in all places log() has been called > before. > Since the user of these traits is the only place where such semantic is > sensibly defined, the method in the class body is overriding the traits > methods, and can access aliases you > introduced for the traits' methods. The way it works right now, on conflict, a class may access the trait method via the alias, or its own overriden copy by the conflicting name. What is a trait to do? It can't access its own method at all as it doesn't "know" the alias. The way this is implemented makes no sense, I'm afraid. > Let's use your example and make something more complex out of it: > > trait T { > function bar(){ $this->print(); > $str = 'print'; > $this->$str(); } > function print() { echo 'trait'; } > } > > > class C { > use T { print as foo; } > } > > What is supposed to happen in this example if we assume renaming? > Would you expect the first function call to print() in bar() to work after > the renaming? > Would you expect the second call, using metaprogramming, to work as well? It's very simple: 1) *only* the original name should work for methods defined in a trait (including metacalls). 2) *only* the new name should work from methods defined in the using class (including metacalls). Yes, I know: this is a lot more complicated to implement. *But* if we'll take shortcuts in user-facing behavior just because it's simpler to implement, then aliasing should've have never been added at all for 5.4, until it can be implemented reasonably. > If we use aliasing instead of renaming, we have predictable behavior for > all options. It's not predictable at all. If the class defines "function print" in your example above, the trait suddenly can't call it's own method anymore! Metacall or not. > Please do me the favor and consult the mailing list archives. > It is all in the various discussions. If behavior specification and reasoning worked by consulting the archives for internals, we wouldn't have RFCs. I see no good reasoning in the RFC for this behavior, and going though thousands of emails in the archive is not a reasonable way to find out the reasoning. > There is no proper way to handle state, state requires splitting, merging, > and what not. None of the research prototypes provides a simple solution. State does not require splitting, merging. What does state "splitting" even mean? Here's a very simple design principle here: if you can't guarantee correctness for a behavior, provide a limited behavior, which guarantees correctness. This is how language design works. If there's a conflict, die with a fatal error, make people rename their properties so there's no conflict. Assuming *silently* that the user is intentionally colliding state variables between traits because he/she wants to merge/split state is insanity IMO. > The solution we have is a 'best effort' solution. > If you can do better, please make a proposal. I did in my original email. No property collisions. Fatal errors. It's very simple. > I assume we are talking about: > http://php.net/manual/en/language.oop5.traits.php > > Static variables and members/properties are not related at all. The writer > of the documentation didn't get the wording correct. Please feel free to > submit a patch. I've submitted a doc bug. No one want to fix it since they think it's PHP that's wrong, not the manual. I can't do anything more about it. Here's the link: https://bugs.php.net/bug.php?id=62156 Stan