Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43731 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15045 invoked from network); 18 Apr 2009 18:19:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Apr 2009 18:19:44 -0000 Authentication-Results: pb1.pair.com header.from=sv_forums@fmethod.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=sv_forums@fmethod.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fmethod.com from 69.16.228.148 cause and error) X-PHP-List-Original-Sender: sv_forums@fmethod.com X-Host-Fingerprint: 69.16.228.148 unknown Linux 2.4/2.6 Received: from [69.16.228.148] ([69.16.228.148:53151] helo=host.fmethod.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FB/E3-24459-FB91AE94 for ; Sat, 18 Apr 2009 14:19:44 -0400 Received: from [83.228.56.37] (port=3888 helo=pc) by host.fmethod.com with esmtpa (Exim 4.69) (envelope-from ) id 1LvF8e-0008Ar-Cs for internals@lists.php.net; Sat, 18 Apr 2009 13:19:40 -0500 Message-ID: To: References: <52F25C37-F12D-4A85-A7D3-C579637B56C5@stefan-marr.de> <3B04560F-97DC-423D-8606-3436F28EF2D1@stefan-marr.de> <7CC5C4E4-5DBC-4B86-8F69-E786DD2BDE02@stefan-marr.de> Date: Sat, 18 Apr 2009 21:19:31 +0300 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="ISO-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - host.fmethod.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - fmethod.com Subject: Re: [PHP-DEV] Grafts, Traits, horizontal reuse From: sv_forums@fmethod.com ("Stan Vassilev | FM") > trait Counter { > var $value; > public function inc() { $this->value++; } > ... > } > > trait Color { > var $hue; > var $saturation; > var $value; > public function getRGB() { /* ... */} > ... > } > > class MyClass { > use Counter, Color; > } > > Ok, you could argue that you than will have to refactor your property > names in your state. But then you will break other traits. Even worth, > this trait is defined in a widely used framework and your breaking other > peoples code just by changing implementation details which should not > even be visible to your users. > > I do not think that this simple model is practicable. Unfortunately, it > is implied by the current state-less proposal, if we do not forbid any > access to properties inside of trait methods (which sounds like a stupid > idea to me). :( > > Regards > Stefan Hi, Since the expectancy of a trait is it'll be used in many other classes horizontally, I wouldn't think people will start taking generic names in traits as they do in normal classes. I'd personally expect this naming convention more likely: trait Counter { protected $counterValue; } trait Observable { protected $observableListeners; } And so on. The benefit is it's easy to implement, understand, and use. However if this is not acceptable to many, and we could live with the complication of it, the best idea for trait property access I suppose would be this: trait Observable { protected $listeners; } class Any { use Observable; function accessTraitProperty() { var_dump($this->Observable->listeners); } } Hence namespacing trait state into an automatically created object of the same name, and we're done. On the other said, a all traits could have an automatic property "owner", which gives it access to the class state/properties. Regards, Stan Vassilev