Re: Traits and Properties
| From: | Stefan Marr | Date: | Thu, 06 Jan 2011 13:38:34 +0000 |
| Subject: | Re: Traits and Properties | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51231@lists.php.net to get a copy of this message | ||
Hi Jonathan:
Sorry, was not able to get back to those discussions earlier.
On 22 Dec 2010, at 16:39, Jonathan Bond-Caron wrote:
> There are two remaining questions I have:
> 1) How do traits affect the reflection API?
Johannes implemented some features in the Reflection API.
However, they are very ad-hoc, and there are some points which could be designed differently to make
the concepts more clear.
On of those things is that you actually use ReflectionClass to reflect on a trait.
That is really an implementation detail, and should be changed to not confuse anyone on a
conceptional level. We should not expose that kind of engine/implementation detail.
Thus, there remains stuff to be done about reflection. In general, I would like to be able to access
all information that was in the source code. However, time constraints are an issue for me. If there
would be a new release date for an alpha or something, I think I could get some time to work on
it...
> 2) Do we want to be able to declare trait requirements for properties and
> methods? If so what syntax?
Well, there was the proposal to use require to express constraints for the composing class, which is
something I liked.
However, I would not go to support properties, too, since I still maintain the opinion that we do
not actually do something about state with regard to traits.
>
> A note on the syntax proposed by Nathan:
> trait require Foo
>
> An option could be:
>
> trait Foo {
> require {
> public $var;
> function ratio();
> }
Hm, well, we already got abstract methods for the methods part.
> trait Bar {
> require interface Iterator;
> }
And expressing the requirement for an interface or an abstract class seems to be the only thing
missing, I think.
However, I would not put that in the body but into the hat.
trait Bar require OneSpecificClass, AndPossiblyAnInterface, OrPossiblyAnotherInterface {}
>
> The idea comes from:
> http://code.google.com/p/es-lab/wiki/Traits
>
> I found this trying to look for alternative keyword for 'require'.
Yes, Tom worked on that a while ago, but it was to easy to implement it in a library for JavaScript.
To easy to be considered for a language feature...
Best regards
Stefan
--
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax: +32 2 629 3525