Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43727 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11717 invoked from network); 17 Apr 2009 21:45:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2009 21:45:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@stefan-marr.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@stefan-marr.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain stefan-marr.de from 85.88.12.247 cause and error) X-PHP-List-Original-Sender: php@stefan-marr.de X-Host-Fingerprint: 85.88.12.247 toolslave.net Received: from [85.88.12.247] ([85.88.12.247:48445] helo=uhweb12247.united-hoster.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6A/58-25341-888F8E94 for ; Fri, 17 Apr 2009 17:45:46 -0400 Received: from 201.58-65-87.adsl-dyn.isp.belgacom.be ([87.65.58.201] helo=[192.168.1.21]) by uhweb12247.united-hoster.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1Luvs1-0007vI-IU; Fri, 17 Apr 2009 23:45:33 +0200 Cc: internals@lists.php.net Message-ID: <3B04560F-97DC-423D-8606-3436F28EF2D1@stefan-marr.de> To: Tom Boutell In-Reply-To: Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Date: Fri, 17 Apr 2009 23:45:11 +0200 References: <52F25C37-F12D-4A85-A7D3-C579637B56C5@stefan-marr.de> X-Mailer: Apple Mail (2.930.3) Subject: Re: [PHP-DEV] Grafts, Traits, horizontal reuse From: php@stefan-marr.de (Stefan Marr) Hi Tom, On 17 Apr 2009, at 19:20, Tom Boutell wrote: >> How ever, there are also corner cases. (Behavior might be different >> in case >> of name clashes for dynamically created properties within a >> composition, >> changing behavior depending on the order of method invocations on a >> single >> object) > > I'm not sure I grasp how these can happen in this scenario. Well, it actually depends on the strictness of this idea. And its particular implementation. With the dynamic nature of PHP in mind, my first idea would be something like this, which is not ideal: class Base { // private $a; <- intentionally left out because of // some smart approach to use meta-programming powers... public function setA($value) { $this->a = $value; } public function echoA() { echo $this->a; } } trait TraitUsingA { // var $a; <- intentionally left out because of another smart approach for using // really clever meta-programming, not shown here public function setTraitA($value) { $this->a = $value; } public function echoTraitA() { echo $this->a; } } class MyClass { use TraitUsingA; } $a = new MyClass(); $a->setTraitA('trait'); $a->setA('base'); $a->echoTraitA(); // echos 'trait' $a->echoA(); // echos 'base' $b = new MyClass(); $b->setA('base'); $b->setTraitA('trait'); $b->echoTraitA(); // echos 'trait' $b->echoA(); // echos 'trait' The question here is how to handle property accesses, in particular accesses to unspecified properties. I actually would expect to have a lookup mechanism which first looks in the trait, and if the property is not found there, its going to the object. I expect this behavior, because it is similar to what we have with inheritance and properties defined by a superclass. If a property is not jet defined, I would expect it to be created in the most inner scope, like local variables. On the other hand, I also would expect, as in inheritance, properties to be found defined by super classes, or the class which defines the composition. But this only my intuitive solution, so this could of course be specified different. Best regards Stefan -- Stefan Marr Programming Technology Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://prog.vub.ac.be/~smarr