Hello All,
I'm new to this list, so please excuse me if this subject was already discussed, or proposed.
I've made an experimental patch to ZendEngine/PHP (5.3.5) to allow native annotations (without doc comments), using the token @@ (the @ was already taken). It allows 0 or more annotations (with 0 or more arguments each one) for classes, properties, methods, and arguments for methods, like:
@@Annotation(key="value1")
class A {
@@Annotation(key="value1")
private $property;
@@Annotation(key="value1")
private function aMethod(@@Annotation(key="value1") @@Annotation2 $a, $b) {
...
}
}
The patch can be found at: https://github.com/marcelog/AnoForPHP.
The annotations and their optional arguments can be retrieved via the getAnnotations() method of ReflectionClass, ReflectionMethod, ReflectionParameter, and ReflectionProperty.
I plan to extend this patch with some extended functionality, like having PHP instantiate a given class for the given annotation. By using convention instead of configuration, the name of the annotation is the name of the class, which should also extend some PHP base class, like "Annotation".
I'm basically looking for comments on the patch and the functionality, since I'm new to the ZendEngine as well.
Again, I'm sorry if this post should not go here or there is not interest in such a feature in the language itself. Also, if I missed something in the code of the patch, because it's more like a proof-of-concept than a final formal proposal.
Regards!
--
// I don't sleep. I coffee.
"Make everything as simple as possible, but not simpler." -- Albert Einstein "The class object inherits from Chuck Norris." "Chuck Norris can divide by zero and can unit test an entire application with a single assert."
"There’s a lot of work happening behind the scenes, courtesy of the Spring AOP framework"
"Why do I have this nagging hunch that you have no idea what you're doing?" "Any society that would give up a little liberty to gain a little security will deserve neither and lose both" - Benjamin Franklin
Hello All,
I'm new to this list, so please excuse me if this subject was already discussed, or proposed.
Hi,
it has already been discussed with length. Please take a look at:
http://wiki.php.net/rfc/annotations
it would be more productive if you explain in what ways your proposal differs from the one above, and why that should be so.
Best,
Quoted text · 18 lines
I've made an experimental patch to ZendEngine/PHP (5.3.5) to allow native annotations (without doc comments), using the token @@ (the @ was already taken). It allows 0 or more annotations (with 0 or more arguments each one) for classes, properties, methods, and arguments for methods, like:
@@Annotation(key="value1")
class A {
@@Annotation(key="value1")
private $property;@@Annotation(key="value1") private function aMethod(@@Annotation(key="value1") @@Annotation2 $a, $b) { ... }}
The patch can be found at: https://github.com/marcelog/AnoForPHP.
The annotations and their optional arguments can be retrieved via the getAnnotations() method of ReflectionClass, ReflectionMethod, ReflectionParameter, and ReflectionProperty.
I plan to extend this patch with some extended functionality, like having PHP instantiate a given class for the given annotation. By using convention instead of configuration, the name of the annotation is the name of the class, which should also extend some PHP base class, like "Annotation".
I'm basically looking for comments on the patch and the functionality, since I'm new to the ZendEngine as well.
Again, I'm sorry if this post should not go here or there is not interest in such a feature in the language itself. Also, if I missed something in the code of the patch, because it's more like a proof-of-concept than a final formal proposal.
Regards!
--
// I don't sleep. I coffee.
"Make everything as simple as possible, but not simpler." -- Albert Einstein "The class object inherits from Chuck Norris." "Chuck Norris can divide by zero and can unit test an entire application with a single assert."
"There’s a lot of work happening behind the scenes, courtesy of the Spring AOP framework"
"Why do I have this nagging hunch that you have no idea what you're doing?" "Any society that would give up a little liberty to gain a little security will deserve neither and lose both" - Benjamin Franklin
it has already been discussed with length. Please take a look at:
http://wiki.php.net/rfc/annotations
Thank you for the link. That is actually pretty much what I intended to do. The only difference with my own version lies in the possibility to annotate method parameters (very useful in many cases when using an IoC/DI container). So that would be my 2 cents there.
I made the patch because it's a feature I wanted from a long time now, and didn't find anything done about it. Do you know if this rfc is going to be approved?
Thanks again for your quick reply,
Quoted text · 4 lines
it has already been discussed with length. Please take a look at:
http://wiki.php.net/rfc/annotations
Thank you for the link. That is actually pretty much what I intended to do. The only difference with my own version lies in the possibility to annotate method parameters (very useful in many cases when using an IoC/DI container). So that would be my 2 cents there.I made the patch because it's a feature I wanted from a long time now, and didn't find anything done about it. Do you know if this rfc is going to be approved?
The main concern with the proposals above were:
-
the syntax
-
how to represent the data (i.e. objects)
-
if objects, when to instanciate them, when reflecting, once?
I don't believe the patch was anywhere near an accepted state back then, sadly.
Best,
Thanks again for your quick reply,
I don't believe the patch was anywhere near an accepted state back then, sadly.
Are you saying there wont be annotations in PHP? Is there any way to contribute to make this feature accepted and available?
No, only that no compromise has been reached on annotation support.
--
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hi all,
I promise myself to not revamp this discussion again, but it wasn't me this time!
@Etienne: That RFC is outdated.
Since the last feedback form internals list, a lot of changes have been made to that RFC. Maybe I should update it ASAP so you can clearly understand what have changed to be compatible with current PHP syntax.
If you are interested, Pierrick moved all the recent developments to a github repository, which can be reached here: https://github.com/adoy/PHP-Annotations
Take a look at some tests:
https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/parser_021.phpt https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/ReflectionParameter_getAnnotations_003.phpt https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/ReflectionClass_getAnnotations_004.phpt
Also, there's even an alternative patch that support positioned parameters instead of named ones.
We just have to reach an agreement with what PHP core want.
@Marcelo: While your proposal looks very good, it lacks of the support to nested Annotation.
Consider how userland/framework would use your idea. For example, Symfony2 supports validation of data inside classes inspired on JSR-303 (Bean Validation).
Symfony2 takes an advantage of a library Doctrine group (which I'm a core member) created by parsing docblocks. When we created this parser, I created this RFC with the good intention that PHP could benefit of this known feature to enhance current userland developments.
The first thing you need is your application still running ok with and without comments. This already breaks all suggestions of creating a PECL extension of docblock parser.
I'd like to see what people think about it and make something "IN" on next PHP major version.
Cheers,
Quoted text · 7 lines
I don't believe the patch was anywhere near an accepted state back then, sadly.
Are you saying there wont be annotations in PHP? Is there any way to contribute to make this feature accepted and available?No, only that no compromise has been reached on annotation support.
--
Pierre@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
--
--
Guilherme Blanco
Mobile: +55 (16) 9215-8480
MSN: guilhermeblanco@hotmail.com
São Paulo - SP/Brazil
The presented patch is just a quick and dirty work that I could put together in 2 days, with knowledge of the zend engine. Thanks to some tips from Pierrick, I'm slowly improving its quality.
However my ideal goals are pretty close to what you have done in your rfc. Today Pierrick added the possibility to annotate method parameters just like in the patch I sent, so I'm happy I already contributed with something ;)
I made the patch for similar reasons. I'm the author of Ding (IoC/DI container) and I really dont like having to use doc blocks to support annotations. I think this is an increasing need generally speaking in the php world. If PHP is to be considered some kind of "agile" language, it needs some kind of metadata handling (in this case, annotations).
I think other things can be added to the rfc, like having some annotations supported by php itself (@Init, @Destroy, @Configuration). This would need to be instantiated and "run" as soon as the annotation is detected. This could be accomplished by either php or c code, so the behavior can be extended via pecl extensions and/or normal php code.
On Mon, Mar 14, 2011 at 3:02 PM, guilhermeblanco@gmail.com guilhermeblanco@gmail.com wrote:
Quoted text · 27 lines
Hi all,
I promise myself to not revamp this discussion again, but it wasn't me this time!
@Etienne: That RFC is outdated.
Since the last feedback form internals list, a lot of changes have been made to that RFC. Maybe I should update it ASAP so you can clearly understand what have changed to be compatible with current PHP syntax.If you are interested, Pierrick moved all the recent developments to a github repository, which can be reached here: https://github.com/adoy/PHP-Annotations
Take a look at some tests:
https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/parser_021.phpt https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/ReflectionParameter_getAnnotations_003.phpt https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/ReflectionClass_getAnnotations_004.phptAlso, there's even an alternative patch that support positioned parameters instead of named ones.
We just have to reach an agreement with what PHP core want.@Marcelo: While your proposal looks very good, it lacks of the support to nested Annotation.
Consider how userland/framework would use your idea. For example, Symfony2 supports validation of data inside classes inspired on JSR-303 (Bean Validation).Symfony2 takes an advantage of a library Doctrine group (which I'm a core member) created by parsing docblocks. When we created this parser, I created this RFC with the good intention that PHP could benefit of this known feature to enhance current userland developments.
The first thing you need is your application still running ok with and without comments. This already breaks all suggestions of creating a PECL extension of docblock parser.I'd like to see what people think about it and make something "IN" on next PHP major version.
Cheers,
I don't believe the patch was anywhere near an accepted state back then, sadly.
Are you saying there wont be annotations in PHP? Is there any way to contribute to make this feature accepted and available?No, only that no compromise has been reached on annotation support.
--
Pierre@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
--
--
Guilherme Blanco
Mobile: +55 (16) 9215-8480
MSN: guilhermeblanco@hotmail.com
São Paulo - SP/Brazil
--
--
// I don't sleep. I coffee.
"Make everything as simple as possible, but not simpler." -- Albert Einstein "The class object inherits from Chuck Norris." "Chuck Norris can divide by zero and can unit test an entire application with a single assert."
"There’s a lot of work happening behind the scenes, courtesy of the Spring AOP framework"
"Why do I have this nagging hunch that you have no idea what you're doing?" "Any society that would give up a little liberty to gain a little security will deserve neither and lose both" - Benjamin Franklin
Hi Guilherme.
@Etienne: That RFC is outdated.
Since the last feedback form internals list, a lot of changes have been made to that RFC. Maybe I should update it ASAP so you can clearly understand what have changed to be compatible with current PHP syntax.
I think having the RFC up-to-date is a must to get this rolling (again). So, please, do it! :)
I'd like to see what people think about it and make something "IN" on next PHP major version.
I honestly think I can speak for the whole FLOW3[1] developer and user base in this regard. With that said, I would love to see native annotation support in PHP!
If you need support and/or testing targets, get in touch!
Regards,
Karsten
Hi Karsten,
Quoted text · 4 lines
Hi Guilherme.
@Etienne: That RFC is outdated.
Since the last feedback form internals list, a lot of changes have been made to that RFC. Maybe I should update it ASAP so you can clearly understand what have changed to be compatible with current PHP syntax.I think having the RFC up-to-date is a must to get this rolling (again). So, please, do it! :)
As you may know, the wiki website is currently unavailable for an unknown period. We can't update the RFC now but we'll do it for sure when the wiki will be up and running again.
I'd like to see what people think about it and make something "IN" on next PHP major version.
I honestly think I can speak for the whole FLOW3[1] developer and user base in this regard. With that said, I would love to see native annotation support in PHP!
If you need support and/or testing targets, get in touch!
Like Guilherme said, you can start playing with the native annotation support in PHP by applying the patch (
http://www.adoy.net/php/Annotations.php ) on trunk or you can also just do a checkout of the git repository ( https://github.com/adoy/PHP-Annotations ). You'll find some existing tests/examples in the tests/annotation folder. Every feedback on this implementation is of course welcome and will help us improve it so that it might be one day in PHP.
Quoted text · 4 lines
Regards,
Karsten--
Cheers,
Pierrick
On Mon, Mar 14, 2011 at 7:02 PM, guilhermeblanco@gmail.com < guilhermeblanco@gmail.com> wrote:
Quoted text · 16 lines
Hi all,
I promise myself to not revamp this discussion again, but it wasn't me this time!
@Etienne: That RFC is outdated.
Since the last feedback form internals list, a lot of changes have been made to that RFC. Maybe I should update it ASAP so you can clearly understand what have changed to be compatible with current PHP syntax.If you are interested, Pierrick moved all the recent developments to a github repository, which can be reached here: https://github.com/adoy/PHP-Annotations
Take a look at some tests:
https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/parser_021.phpt
Also, there's even an alternative patch that support positioned parameters instead of named ones.
We just have to reach an agreement with what PHP core want.@Marcelo: While your proposal looks very good, it lacks of the support to nested Annotation.
Consider how userland/framework would use your idea. For example, Symfony2 supports validation of data inside classes inspired on JSR-303 (Bean Validation).Symfony2 takes an advantage of a library Doctrine group (which I'm a core member) created by parsing docblocks. When we created this parser, I created this RFC with the good intention that PHP could benefit of this known feature to enhance current userland developments.
The first thing you need is your application still running ok with and without comments. This already breaks all suggestions of creating a PECL extension of docblock parser.I'd like to see what people think about it and make something "IN" on next PHP major version.
now that the wiki is back and this was brought up in the 5.4 release planning, I think it would be a good idea to:
- update the RFC to be in sync with the implementation
- review the rfc and the patch itself
- make the necessary modifications if necessary
- decide whether we want this in 5.4 or not.
Tyrael
Hi Ferenc,
I'll update the RFC to match the current implementation. Pierrick is working to extract a diff more simplified so you can quickly look at it.
Thanks.
Quoted text · 22 lines
On Mon, Mar 14, 2011 at 7:02 PM, guilhermeblanco@gmail.com guilhermeblanco@gmail.com wrote:
Hi all,
I promise myself to not revamp this discussion again, but it wasn't me this time!
@Etienne: That RFC is outdated.
Since the last feedback form internals list, a lot of changes have been made to that RFC. Maybe I should update it ASAP so you can clearly understand what have changed to be compatible with current PHP syntax.If you are interested, Pierrick moved all the recent developments to a github repository, which can be reached here: https://github.com/adoy/PHP-Annotations
Take a look at some tests:
https://github.com/adoy/PHP-Annotations/blob/master/tests/annotations/parser_021.phpt
Also, there's even an alternative patch that support positioned parameters instead of named ones.
We just have to reach an agreement with what PHP core want.@Marcelo: While your proposal looks very good, it lacks of the support to nested Annotation.
Consider how userland/framework would use your idea. For example, Symfony2 supports validation of data inside classes inspired on JSR-303 (Bean Validation).Symfony2 takes an advantage of a library Doctrine group (which I'm a core member) created by parsing docblocks. When we created this parser, I created this RFC with the good intention that PHP could benefit of this known feature to enhance current userland developments.
The first thing you need is your application still running ok with and without comments. This already breaks all suggestions of creating a PECL extension of docblock parser.I'd like to see what people think about it and make something "IN" on next PHP major version.
now that the wiki is back and this was brought up in the 5.4 release planning, I think it would be a good idea to:
- update the RFC to be in sync with the implementation
- review the rfc and the patch itself
- make the necessary modifications if necessary
- decide whether we want this in 5.4 or not. Tyrael
--
Guilherme Blanco
Mobile: +55 (16) 9215-8480
MSN: guilhermeblanco@hotmail.com
São Paulo - SP/Brazil
it has already been discussed with length. Please take a look at:
http://wiki.php.net/rfc/annotations
Thank you for the link. That is actually pretty much what I intended to do. The only difference with my own version lies in the possibility to annotate method parameters (very useful in many cases when using an IoC/DI container). So that would be my 2 cents there.
I haven't read the RFC, but what you suggested in your earlier email looked good to me, and I like the idea, so I'd be in favour of doing something. (I'm new here, too, and not a core dev or anything, so my opinion doesn't and shouldn't carry much weight, but there it is.)
Ben.