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:
<?php
class Foo {
use Bar {
not foo1;
clone foo1 as barFoo1;
}
}
Cloning I think gives us the correct idea of what is actually happening:
the entire body of method foo1 is copied to a new method called barFoo1.
Also, using `not` for exclusion also gets my vote (although I doubt my
vote actually matters).
--
"Joshua Thompson" <[EMAIL PROTECTED]>
<http://www.schmalls.com>
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php