Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35763 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5899 invoked by uid 1010); 23 Feb 2008 22:38:46 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 5884 invoked from network); 23 Feb 2008 22:38:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Feb 2008 22:38:46 -0000 X-Host-Fingerprint: 72.198.16.221 ip72-198-16-221.ok.ok.cox.net Received: from [72.198.16.221] ([72.198.16.221:7567] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/D7-30812-570A0C74 for ; Sat, 23 Feb 2008 17:38:45 -0500 Message-ID: <8F.D7.30812.570A0C74@pb1.pair.com> To: internals@lists.php.net Date: Sat, 23 Feb 2008 16:38:45 -0600 User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 References: <47BD207C.2080905@chiaraquartet.net> <47BD928E.8080006@cschneid.com> <47BE6413.6090507@chiaraquartet.net> <47BEFDFE.909@cschneid.com> In-Reply-To: <47BEFDFE.909@cschneid.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 080222-0, 02/22/2008), Outbound message X-Antivirus-Status: Clean X-Posted-By: 72.198.16.221 Subject: Re: Trait aliasing syntax suggestions From: spam.goes.in.here@gmail.com (Joshua Thompson) >>> Another detail: The implementation of the parser changes should still >>> allow a class or function called "trait", i.e. "trait" should only be a >>> keyword at specific positions in the source to avoid unneccesary BC >>> breaks. The current patch has this BC problem. >> >> This is not possible to implement, having tried to do a similar thing >> for 'import' and 'namespace.' The reason is that we can encounter a >> classname at any point thanks to "classname::whatever" syntax, so it >> slows the lexer down a bit in that for every T_TRAIT we would have to >> check to see if the next 2 characters are ::, and makes the lexer >> uber-complicated. It's a big mess. > > I think this is a point we should take seriously. I see the following > solutions: > 1. Wait with the introduction until either the parser allows such an > addition without BC break or wait for the appropriate PHP release. (Is > 5.3 the time to introduce this BC break? I don't know the current PHP > definitions about major/minor releases) > 2. Consider this issue carefully when deciding on a syntax. Maybe favour > a syntax with fewer new keywords. Reusing keywords like "include", "as" > or "not" come to mind. If the namespace patch is in PHP 5.3 (it is in the snapshots) then we are already introducing the new keyword `namespace` that will break BC. I think we can take this as reason enough to go ahead and add the `trait` keyword. And since we have the following complementary keywords: - `class` and `extends` - `interface` and `implements` - `namespace` and `use` - etc. we should go ahead and introduce the complimentary keyword for `trait`, and it doesn't make much sense to reuse one of the other keywords. There are already some suggestions on Stefan's RFC, but none of them seem to fit as well to me. I think we should throw `import` back onto namespaces and use `use` with traits. The `use` or `uses` keyword is consistent with other implementations of traits. And if nobody likes that idea, what about `inline`, `inject`, `insert`, `add`, or even `+`. I also have an idea for aliasing that I don't think anyone has thought of yet: reusing the `clone` keyword like so: