Re: [PHP-DEV] Re: Annotations in PHP7

2015-02-17 Thread Dmitry Stogov
On Tue, Feb 17, 2015 at 4:50 PM, François Laupretre franc...@php.net
wrote:

 HI Dmitry,

 Question : in which scope do you evaluate the PHP expression ?


We don't evaluate expressions. We just store them. Evaluation and/or
modification is a subject for future development.



 Example :

 DbC.requires($a  0);
 DbC.ensures(__RETURN__  0);

 function foo($a)
 {
 ...

 How can you know from this that the first expression must be evaluated at
 function entry, that the second one must be interpreted when function
 exits, let alone the question of __RETURN__ replacement and external switch
 to authorize/disable DbC evaluations.


If we will support such DbC approach, then an additional extension may use
this attributes to insert their code into appropriate places of main
function.

Thanks. Dmitry.


 Several people rightly stated that expression would be computed at compile
 time. That's a way to solve the scope question as it practically means that
 expressions are evaluated in the global scope, but DbC must evaluate its
 expressions at runtime. Does it mean we should write 'DbC.requires('$a 
 0') ? Not very intuitive but that's probably the only solution.

 Something else : I am not sure I understand, but do you intend evaluating
 annotation expressions everytime you parse the file. Or would you provide a
 global switch ?

  Any one can use doc-block now and later, but php core won't parse
 doc-blocks. It's a task for external tools.

 I understand. Actually, DbC is not the perfect use case for annotations.
 It would be fine to find a good use case because neither of DbC, AOP,
 Doctrine, or phpdoc fit so well.

 There comes my last question : is it so interesting and mandatory to
 implement annotations in the core, instead of an extension which would
 parse doc blocks when needed, and would return bare strings through a
 reflection-like API ? I know most want to put annotations in the core, but
 what's the real benefit, if we don't consider performance ? Do we have use
 cases comparing both approaches ?

 The fact that we voluntarily make it incompatible with phpdoc and doctrine
 'annotations' saddens me a bit too because people used to the current
 'annotation' meaning will have to integrate that a new PHP native
 'annotation' feature, totally different from what they've been using for
 years. And doctrine is not an edge-case. If there are good reasons, why
 not, but I don't see them yet.

 Regards

 François






RE: [PHP-DEV] Re: Annotations in PHP7

2015-02-17 Thread François Laupretre
HI Dmitry,

Question : in which scope do you evaluate the PHP expression ?

Example :

DbC.requires($a  0);
DbC.ensures(__RETURN__  0);

function foo($a)
{
...

How can you know from this that the first expression must be evaluated at 
function entry, that the second one must be interpreted when function exits, 
let alone the question of __RETURN__ replacement and external switch to 
authorize/disable DbC evaluations.

Several people rightly stated that expression would be computed at compile 
time. That's a way to solve the scope question as it practically means that 
expressions are evaluated in the global scope, but DbC must evaluate its 
expressions at runtime. Does it mean we should write 'DbC.requires('$a  0') 
? Not very intuitive but that's probably the only solution.

Something else : I am not sure I understand, but do you intend evaluating 
annotation expressions everytime you parse the file. Or would you provide a 
global switch ?

 Any one can use doc-block now and later, but php core won't parse doc-blocks. 
 It's a task for external tools.

I understand. Actually, DbC is not the perfect use case for annotations. It 
would be fine to find a good use case because neither of DbC, AOP, Doctrine, or 
phpdoc fit so well.

There comes my last question : is it so interesting and mandatory to implement 
annotations in the core, instead of an extension which would parse doc blocks 
when needed, and would return bare strings through a reflection-like API ? I 
know most want to put annotations in the core, but what's the real benefit, if 
we don't consider performance ? Do we have use cases comparing both approaches ?

The fact that we voluntarily make it incompatible with phpdoc and doctrine 
'annotations' saddens me a bit too because people used to the current 
'annotation' meaning will have to integrate that a new PHP native 'annotation' 
feature, totally different from what they've been using for years. And doctrine 
is not an edge-case. If there are good reasons, why not, but I don't see them 
yet.
 
Regards

François




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Rowan Collins
On Mon, Feb 16, 2015 at 6:41 PM, Rowan Collins rowan.coll...@gmail.com 
mailto:rowan.coll...@gmail.com wrote:


   Is there any value in deciding the initial syntax for 7.0, and
   implementing only non-parameterised annotations, i.e. you can call
   hasAnnotation(string): bool but nothing else?


Dmitry Stogov wrote on 16/02/2015 16:02:
this will work, of course, and robust implementation wouldn't take 
more than a day :)
but it'll require user-level parser again. no big advantage in 
comparison to doc-block.


No user-level parser would be required (or even possible), because 
parameters would be illegal, not just unparsed.


So, for example, the following would be legal in 7.0:

IsMagic
function foo() { }

if ( (new ReflectionFunction('foo'))-hasAnnotation('IsMagic') ) ...


But the following would be illegal, even though a similar syntax would 
be being prototyped for use in 7.1:


HasMagic('Expelliamus!')
function foo() { }

$magic = (new ReflectionFunction('foo'))-getAnnotation('HasMagic');


A few use cases would be possible just with boolean flags, and it would 
give us a base to work with going forward.


It also avoids the situation (as discussed in another thread) of trying 
to implement every detail of the implementation of the feature before 
checking for consensus. In this case we can check that people are in 
favour of:

1) adding annotations as a core feature
2) the basic syntax (Foo, Foo, [Foo], @Foo, etc)

If there's an overwhelming Yes, that's a confidence boost for whoever 
works on the harder parts over the following months.


Regards,
--
Rowan Collins
[IMSoP]




Re: [PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Dmitry Stogov
this will work, of course, and robust implementation wouldn't take more
than a day :)
but it'll require user-level parser again. no big advantage in comparison
to doc-block.

Thanks. Dmitry.




On Mon, Feb 16, 2015 at 6:41 PM, Rowan Collins rowan.coll...@gmail.com
wrote:

 Nikita Popov wrote on 16/02/2015 12:14:

 I think this is a great idea, but we should postpone it to PHP 7.1.
 Especially if you want to make this AST based (which would require both
 stabilizing the AST we return for expressions and having APIs to do
 codegen
 based on the AST) it will require a lot of work both for design and
 implementation. I don't think it's realistic to include a high-quality
 implementation in PHP 7.


 Is there any value in deciding the initial syntax for 7.0, and
 implementing only non-parameterised annotations, i.e. you can call
 hasAnnotation(string): bool but nothing else?

 This wouldn't be enough to migrate existing annotation frameworks or
 implement DbC and AOP, but it would mean we weren't adding a major syntax
 element in a .1 release, which just feels tidier to me somehow.

 It also commits us to a roadmap to implement it, rather than just putting
 off all the decisions for another year.

 Regards,
 --
 Rowan Collins
 [IMSoP]


 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Stanislav Malyshev
Hi!

 The test there is self explainable. Of course, annotations just provide
 a way to add metadata, but doesn't define attribute names or the ways
 they are going to be used. Only Reflection API to read.

Looks fine, but I'm not sure how one can use the AST that the reflection
returns. Is it for extensions only?

Also, for some annotations you want values - i.e. optimization_level,
and for some - expressions. So there should be an easy way to convert
the AST to the actual value for whoever implements the annotation.

 There are still a lot of technical problems that have to be solved.
 Right now, we just need to answer a question - if we like this in PHP7?

I'd like to have some annotations in PHP 7, definitely.

-- 
Stas Malyshev
smalys...@gmail.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Dmitry Stogov
On Mon, Feb 16, 2015 at 8:41 PM, Stanislav Malyshev smalys...@gmail.com
wrote:

 Hi!

  The test there is self explainable. Of course, annotations just provide
  a way to add metadata, but doesn't define attribute names or the ways
  they are going to be used. Only Reflection API to read.

 Looks fine, but I'm not sure how one can use the AST that the reflection
 returns. Is it for extensions only?


I don't know the best way yet.
Nikita worked in extension for AST traversing in PHP.



 Also, for some annotations you want values - i.e. optimization_level,
 and for some - expressions. So there should be an easy way to convert
 the AST to the actual value for whoever implements the annotation.


agree.

Thanks. Dmitry.


  There are still a lot of technical problems that have to be solved.
  Right now, we just need to answer a question - if we like this in PHP7?

 I'd like to have some annotations in PHP 7, definitely.

 --
 Stas Malyshev
 smalys...@gmail.com



Re: [PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Dmitry Stogov
this won't implement features necessary for phpDocumentor, Doctrine, etc.


On Mon, Feb 16, 2015 at 8:29 PM, Rowan Collins rowan.coll...@gmail.com
wrote:

 On Mon, Feb 16, 2015 at 6:41 PM, Rowan Collins rowan.coll...@gmail.com
 mailto:rowan.coll...@gmail.com wrote:

Is there any value in deciding the initial syntax for 7.0, and
implementing only non-parameterised annotations, i.e. you can call
hasAnnotation(string): bool but nothing else?


 Dmitry Stogov wrote on 16/02/2015 16:02:

 this will work, of course, and robust implementation wouldn't take more
 than a day :)
 but it'll require user-level parser again. no big advantage in comparison
 to doc-block.


 No user-level parser would be required (or even possible), because
 parameters would be illegal, not just unparsed.

 So, for example, the following would be legal in 7.0:

 IsMagic
 function foo() { }

 if ( (new ReflectionFunction('foo'))-hasAnnotation('IsMagic') ) ...


 But the following would be illegal, even though a similar syntax would be
 being prototyped for use in 7.1:

 HasMagic('Expelliamus!')
 function foo() { }

 $magic = (new ReflectionFunction('foo'))-getAnnotation('HasMagic');


 A few use cases would be possible just with boolean flags, and it would
 give us a base to work with going forward.

 It also avoids the situation (as discussed in another thread) of trying to
 implement every detail of the implementation of the feature before checking
 for consensus. In this case we can check that people are in favour of:
 1) adding annotations as a core feature
 2) the basic syntax (Foo, Foo, [Foo], @Foo, etc)

 If there's an overwhelming Yes, that's a confidence boost for whoever
 works on the harder parts over the following months.


 Regards,
 --
 Rowan Collins
 [IMSoP]





Re: [PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Rowan Collins

Dmitry Stogov wrote on 16/02/2015 18:41:

this won't implement features necessary for phpDocumentor, Doctrine, etc.


I know.

Like I say, it's just a way of keeping things moving, rather than saying 
eh, maybe next year.


It allows us to formally agree the feature, the roadmap, the basic 
syntax, and have a small feature that might be useful for a handful of 
people, while leaving wide open what would go in the parameter brackets, 
and how it would be parsed and presented to userland.



(Also, please stop top-posting, per 
http://git.php.net/?p=php-src.git;a=blob_plain;f=README.MAILINGLIST_RULES;hb=HEAD)


Cheers,
--
Rowan Collins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Yasuo Ohgaki
Hi Dmitry,

On Mon, Feb 16, 2015 at 8:07 PM, Dmitry Stogov dmi...@zend.com wrote:

 During discussion of different ways of implementing Design by Contract
 we got an idea of using annotations.

 BTW: annotations are useful by their own and may be used for different
 purposes. Support for annotations was proposed long time ago:

 https://wiki.php.net/rfc/annotations
 https://wiki.php.net/rfc/annotations-in-docblock
 https://wiki.php.net/rfc/reflection_doccomment_annotations

 HHVM already implemented similar concept

 http://docs.hhvm.com/manual/en/hack.attributes.php

 I made a quick and dirty PoC that shows how we may implement annotations
 in PHP7 and how powerful they may be :
 https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2

 The test there is self explainable. Of course, annotations just provide a
 way to add metadata, but doesn't define attribute names or the ways they
 are going to be used. Only Reflection API to read.

 There are still a lot of technical problems that have to be solved.
 Right now, we just need to answer a question - if we like this in PHP7?
 Thought and opinions are welcome...


Although, I prefer simple DbC as PHP syntax, my priority is introducing DbC
to PHP. No problem for me.

For both annotation and PHP syntax, we should concentrate simple (i.e.
without strong type safety. Don't read me wrong, I'm not saying without
type check) DbC. IMHO.

Regards,

--
Yasuo Ohgaki
yohg...@ohgaki.net


[PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Yasuo Ohgaki
Hi Dmitry,

On Mon, Feb 16, 2015 at 8:07 PM, Dmitry Stogov dmi...@zend.com wrote:

 During discussion of different ways of implementing Design by Contract
 we got an idea of using annotations.

 BTW: annotations are useful by their own and may be used for different
 purposes. Support for annotations was proposed long time ago:

 https://wiki.php.net/rfc/annotations
 https://wiki.php.net/rfc/annotations-in-docblock
 https://wiki.php.net/rfc/reflection_doccomment_annotations

 HHVM already implemented similar concept

 http://docs.hhvm.com/manual/en/hack.attributes.php

 I made a quick and dirty PoC that shows how we may implement annotations
 in PHP7 and how powerful they may be :
 https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2

 The test there is self explainable. Of course, annotations just provide a
 way to add metadata, but doesn't define attribute names or the ways they
 are going to be used. Only Reflection API to read.

 There are still a lot of technical problems that have to be solved.
 Right now, we just need to answer a question - if we like this in PHP7?
 Thought and opinions are welcome...


I also would like to introduce AOP in the future. (or with it)
I thought something like

https://github.com/AOP-PHP/AOP

is good, but we may use annotations. With annotations, we must
define pointcut/etc manually, but AOP by annotation is more
flexible than AspectJ.

Regards,

--
Yasuo Ohgaki
yohg...@ohgaki.net


Re: [PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Rafael Dohms
On Mon, Feb 16, 2015 at 7:41 PM, Dmitry Stogov dmi...@zend.com wrote:

 this won't implement features necessary for phpDocumentor, Doctrine, etc.


Just be careful here with phpDocumentor, it does not use annotations but
really needs docblocks instead.
Today the overlap between it and doctrine and such is just matching syntax,
but it for example does not support parametrized annotations.

So let's just stick to Doctrine and other annotation specific libs for
reference of userland implementations.


-- 
Rafael Dohms
PHP Evangelist and Community Leader
http://doh.ms
http://www.amsterdamphp.nl http://wwwamsterdamphp.nl


RE: [PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread François Laupretre
Hi Dmitry,

In my mind, annotation syntax was one level lower, dealing with strings of 
unknown syntax, not PHP expressions. Something like :

'*' whitespaces '@' STRING free-string-up-to-eol

This supports :

* @requires $a  0

But also :

* @statement INSERT INTO ?? VALUES (13, 'Phoenix', 'AZ', 33, 112)

Using Reflection, the application would get an array of (STRING = array of 
free-strings-up-to-eol) in order of appearance and that's all for the 
annotation layer. Then, the client has the responsibility to interpret the 
strings the way it wants.

Even if it is a valid PHP expression, getting it as a string is not a problem. 
DbC, for instance, would get the string, eval() them and error if one of them 
evaluates to false. Performance must not be a problem with annotations. This is 
what makes it suitable for DbC or offline metadata.

If we restrict it to a PHP expression, you need to interpret it at compile 
time, which makes the process more complex. I must admit I don't understand the 
reason, as the only one I see is performance. And I am totally out of sync with 
suggestions to include namespaces, nested annotations, or using class constants 
in expressions. I even feel incomfortable because it's just 'PHP code, but 
elsewhere'. I don't see the use case.

About the syntax, I'm probably faulty there, but I don't understand why we 
cannot use doc blocks. That's easy to parse at compile time, the API is easy to 
define, the parser already parses them, and everyone is already using that. 
Existing applications like doctrine just miss the API to use it in a cleaner 
way but it would be 100% compatible. Actually, I saw several people refusing to 
consider doc blocks as annotations but I was never given the reason why. So, I 
am just curious.

Anyway, I don't like the OO features people want to add everywhere. They can 
get strings and inject them to OO, but that's not the role of the annotation 
layer, IMHO.

I definitely prefer the KISS approach.

Regards

François



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Dmitry Stogov
The implementation is not going to be simple, and taking in account other
tasks, it may be difficult to provide high-quality implementation. Lets
look if it's really a desirable feature. Then I may do all my best, or
forget about it by 7.1.

Thanks. Dmitry.

On Mon, Feb 16, 2015 at 3:14 PM, Nikita Popov nikita@gmail.com wrote:

 On Mon, Feb 16, 2015 at 12:07 PM, Dmitry Stogov dmi...@zend.com wrote:

 hi,

 During discussion of different ways of implementing Design by Contract
 we got an idea of using annotations.

 BTW: annotations are useful by their own and may be used for different
 purposes. Support for annotations was proposed long time ago:

 https://wiki.php.net/rfc/annotations
 https://wiki.php.net/rfc/annotations-in-docblock
 https://wiki.php.net/rfc/reflection_doccomment_annotations

 HHVM already implemented similar concept

 http://docs.hhvm.com/manual/en/hack.attributes.php

 I made a quick and dirty PoC that shows how we may implement annotations
 in PHP7 and how powerful they may be :
 https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2

 The test there is self explainable. Of course, annotations just provide a
 way to add metadata, but doesn't define attribute names or the ways they
 are going to be used. Only Reflection API to read.

 There are still a lot of technical problems that have to be solved.
 Right now, we just need to answer a question - if we like this in PHP7?
 Thought and opinions are welcome...

 Thanks. Dmitry.


 Hi Dmitry!

 I think this is a great idea, but we should postpone it to PHP 7.1.
 Especially if you want to make this AST based (which would require both
 stabilizing the AST we return for expressions and having APIs to do codegen
 based on the AST) it will require a lot of work both for design and
 implementation. I don't think it's realistic to include a high-quality
 implementation in PHP 7.

 As this does not have any BC concerns that I can see, I think it would be
 safer to move this to PHP 7.1, when we will have more time to carefully
 design this.

 Nikita




[PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Dmitry Stogov
On Tue, Feb 17, 2015 at 1:15 AM, Yasuo Ohgaki yohg...@ohgaki.net wrote:

 Hi Dmitry,

 On Mon, Feb 16, 2015 at 8:07 PM, Dmitry Stogov dmi...@zend.com wrote:

 During discussion of different ways of implementing Design by Contract
 we got an idea of using annotations.

 BTW: annotations are useful by their own and may be used for different
 purposes. Support for annotations was proposed long time ago:

 https://wiki.php.net/rfc/annotations
 https://wiki.php.net/rfc/annotations-in-docblock
 https://wiki.php.net/rfc/reflection_doccomment_annotations

 HHVM already implemented similar concept

 http://docs.hhvm.com/manual/en/hack.attributes.php

 I made a quick and dirty PoC that shows how we may implement annotations
 in PHP7 and how powerful they may be :
 https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2

 The test there is self explainable. Of course, annotations just provide a
 way to add metadata, but doesn't define attribute names or the ways they
 are going to be used. Only Reflection API to read.

 There are still a lot of technical problems that have to be solved.
 Right now, we just need to answer a question - if we like this in PHP7?
 Thought and opinions are welcome...


 Although, I prefer simple DbC as PHP syntax, my priority is introducing DbC
 to PHP. No problem for me.


I don't have strong opinion - what is better for DbC, PHP syntax or
annotations.
Now I made some research on annotations, because I think it may be useful
not only for DbC.

Thanks. Dmitry.


 For both annotation and PHP syntax, we should concentrate simple (i.e.
 without strong type safety. Don't read me wrong, I'm not saying without
 type check) DbC. IMHO.

 Regards,

 --
 Yasuo Ohgaki
 yohg...@ohgaki.net



Re: [PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Dmitry Stogov
On Tue, Feb 17, 2015 at 6:45 AM, François Laupretre franc...@php.net
wrote:

 Hi Dmitry,

 In my mind, annotation syntax was one level lower, dealing with strings of
 unknown syntax, not PHP expressions. Something like :

 '*' whitespaces '@' STRING free-string-up-to-eol

 This supports :

 * @requires $a  0


Then you will have to parse the expression your self.


 But also :

 * @statement INSERT INTO ?? VALUES (13, 'Phoenix', 'AZ', 33, 112)


This is not a problem, nobody prohibit quotes.

SQL(INSERT INTO ?? VALUES (13, 'Phoenix', 'AZ', 33, 112))


 Using Reflection, the application would get an array of (STRING = array
 of free-strings-up-to-eol) in order of appearance and that's all for the
 annotation layer. Then, the client has the responsibility to interpret the
 strings the way it wants.

 Even if it is a valid PHP expression, getting it as a string is not a
 problem. DbC, for instance, would get the string, eval() them and error if
 one of them evaluates to false. Performance must not be a problem with
 annotations. This is what makes it suitable for DbC or offline metadata.

 If we restrict it to a PHP expression, you need to interpret it at compile
 time, which makes the process more complex. I must admit I don't understand
 the reason, as the only one I see is performance. And I am totally out of
 sync with suggestions to include namespaces, nested annotations, or using
 class constants in expressions. I even feel incomfortable because it's just
 'PHP code, but elsewhere'. I don't see the use case.

 About the syntax, I'm probably faulty there, but I don't understand why we
 cannot use doc blocks. That's easy to parse at compile time, the API is
 easy to define, the parser already parses them, and everyone is already
 using that. Existing applications like doctrine just miss the API to use it
 in a cleaner way but it would be 100% compatible. Actually, I saw several
 people refusing to consider doc blocks as annotations but I was never given
 the reason why. So, I am just curious.


Any one can use doc-block now and later, but php core won't parse
doc-blocks. It's a task for external tools.


 Anyway, I don't like the OO features people want to add everywhere. They
 can get strings and inject them to OO, but that's not the role of the
 annotation layer, IMHO.

 I definitely prefer the KISS approach.


I'm agree.

Thanks. Dmitry.




 Regards

 François





[PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Pierre Joye
On Mon, Feb 16, 2015 at 3:07 AM, Dmitry Stogov dmi...@zend.com wrote:
 hi,

 During discussion of different ways of implementing Design by Contract we
 got an idea of using annotations.

Thanks a lot to push that forward!

 BTW: annotations are useful by their own and may be used for different
 purposes. Support for annotations was proposed long time ago:

 https://wiki.php.net/rfc/annotations
 https://wiki.php.net/rfc/annotations-in-docblock
 https://wiki.php.net/rfc/reflection_doccomment_annotations

 HHVM already implemented similar concept

 http://docs.hhvm.com/manual/en/hack.attributes.php

 I made a quick and dirty PoC that shows how we may implement annotations in
 PHP7 and how powerful they may be :
 https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2

 The test there is self explainable. Of course, annotations just provide a
 way to add metadata, but doesn't define attribute names or the ways they are
 going to be used. Only Reflection API to read.

 There are still a lot of technical problems that have to be solved.
 Right now, we just need to answer a question - if we like this in PHP7?
 Thought and opinions are welcome...

Is it the branch/fork available?

I think the best way to validate a soluton (and its specs) is to try
to port existing annotations needs using this syntax (like Doctrine's
one). Even if the syntax is different, it will show if the syntax is
powerful enough to cover what is already used. I am not saying we need
to support everything but only what is necessary to actually implement
existing annotations (which have been used for quite some time and
proven to be very useful) using this syntax.

I would also leave the docblock/comments idea out of the discussions,
it is really not what annotations are. If we can spare us that part of
the debate, we can focus on the actual specs and implementations. :)

Cheers,
-- 
Pierre

@pierrejoye | http://www.libgd.org

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Dmitry Stogov
I decided to explain the proposed annotation syntax in words to avoid
misunderstanding

annotations ::= { annotation }.
annotation   ::= '' STRING '' | '' STRING '(' expr ')' ''.

where expr is regular PHP expression.

Thanks. Dmitry.


On Mon, Feb 16, 2015 at 2:07 PM, Dmitry Stogov dmi...@zend.com wrote:

 hi,

 During discussion of different ways of implementing Design by Contract
 we got an idea of using annotations.

 BTW: annotations are useful by their own and may be used for different
 purposes. Support for annotations was proposed long time ago:

 https://wiki.php.net/rfc/annotations
 https://wiki.php.net/rfc/annotations-in-docblock
 https://wiki.php.net/rfc/reflection_doccomment_annotations

 HHVM already implemented similar concept

 http://docs.hhvm.com/manual/en/hack.attributes.php

 I made a quick and dirty PoC that shows how we may implement annotations
 in PHP7 and how powerful they may be :
 https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2

 The test there is self explainable. Of course, annotations just provide a
 way to add metadata, but doesn't define attribute names or the ways they
 are going to be used. Only Reflection API to read.

 There are still a lot of technical problems that have to be solved.
 Right now, we just need to answer a question - if we like this in PHP7?
 Thought and opinions are welcome...

 Thanks. Dmitry.



Re: [PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Dmitry Stogov
you already have doc-block. nothing should be done in PHP core, but you
have to parse it yourself.
The goal of annotations is to provide standard and powerful way.
On the other hand standard PHP expression syntax may be not enough for all
cases.

Thanks. Dmitry.

On Mon, Feb 16, 2015 at 2:22 PM, Cesar Rodas ce...@rodas.me wrote:


 On 16/02/15 12:19, Dmitry Stogov wrote:
  I decided to explain the proposed annotation syntax in words to avoid
  misunderstanding
 
  annotations ::= { annotation }.
  annotation   ::= '' STRING '' | '' STRING '(' expr ')' ''.
 
  where expr is regular PHP expression.
 Why not doc-block annotations? So it can be parse/understand that is
 already there (Doctrine annotations for instance).

 
  Thanks. Dmitry.
 
 
  On Mon, Feb 16, 2015 at 2:07 PM, Dmitry Stogov dmi...@zend.com wrote:
 
  hi,
 
  During discussion of different ways of implementing Design by Contract
  we got an idea of using annotations.
 
  BTW: annotations are useful by their own and may be used for different
  purposes. Support for annotations was proposed long time ago:
 
  https://wiki.php.net/rfc/annotations
  https://wiki.php.net/rfc/annotations-in-docblock
  https://wiki.php.net/rfc/reflection_doccomment_annotations
 
  HHVM already implemented similar concept
 
  http://docs.hhvm.com/manual/en/hack.attributes.php
 
  I made a quick and dirty PoC that shows how we may implement annotations
  in PHP7 and how powerful they may be :
  https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2
 
  The test there is self explainable. Of course, annotations just provide
 a
  way to add metadata, but doesn't define attribute names or the ways they
  are going to be used. Only Reflection API to read.
 
  There are still a lot of technical problems that have to be solved.
  Right now, we just need to answer a question - if we like this in PHP7?
  Thought and opinions are welcome...
 
  Thanks. Dmitry.
 

 --
 César D. Rodas
 Open Source developer
 +595-983-161124
 PGP: F9ED A265 A3AB C8A1 D145 7368 158A 0336 C707 0AA6





Re: [PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Cesar Rodas

On 16/02/15 12:32, Dmitry Stogov wrote:
 you already have doc-block. nothing should be done in PHP core, but
 you have to parse it yourself.
 The goal of annotations is to provide standard and powerful way.
 On the other hand standard PHP expression syntax may be not enough for
 all cases.

Agreed on that. I just thought it could be wise parse natively what is
already out there. Anyways adapt our DocBlock annotation parsers to
parse both (native PHP annotations and docblocks) shouldn't be that hard
either.

As far as I see annotations are supposed to be accessed through
reflections right? Or will it do something automatically as in Python?

Cheers,


 Thanks. Dmitry.

 On Mon, Feb 16, 2015 at 2:22 PM, Cesar Rodas ce...@rodas.me
 mailto:ce...@rodas.me wrote:


 On 16/02/15 12:19, Dmitry Stogov wrote:
  I decided to explain the proposed annotation syntax in words
 to avoid
  misunderstanding
 
  annotations ::= { annotation }.
  annotation   ::= '' STRING '' | '' STRING '(' expr ')' ''.
 
  where expr is regular PHP expression.
 Why not doc-block annotations? So it can be parse/understand that is
 already there (Doctrine annotations for instance).

 
  Thanks. Dmitry.
 
 
  On Mon, Feb 16, 2015 at 2:07 PM, Dmitry Stogov dmi...@zend.com
 mailto:dmi...@zend.com wrote:
 
  hi,
 
  During discussion of different ways of implementing Design by
 Contract
  we got an idea of using annotations.
 
  BTW: annotations are useful by their own and may be used for
 different
  purposes. Support for annotations was proposed long time ago:
 
  https://wiki.php.net/rfc/annotations
  https://wiki.php.net/rfc/annotations-in-docblock
  https://wiki.php.net/rfc/reflection_doccomment_annotations
 
  HHVM already implemented similar concept
 
  http://docs.hhvm.com/manual/en/hack.attributes.php
 
  I made a quick and dirty PoC that shows how we may implement
 annotations
  in PHP7 and how powerful they may be :
  https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2
 
  The test there is self explainable. Of course, annotations just
 provide a
  way to add metadata, but doesn't define attribute names or the
 ways they
  are going to be used. Only Reflection API to read.
 
  There are still a lot of technical problems that have to be solved.
  Right now, we just need to answer a question - if we like this
 in PHP7?
  Thought and opinions are welcome...
 
  Thanks. Dmitry.
 

 --
 César D. Rodas
 Open Source developer
 +595-983-161124
 PGP: F9ED A265 A3AB C8A1 D145 7368 158A 0336 C707 0AA6




-- 
César D. Rodas
Open Source developer
+595-983-161124
PGP: F9ED A265 A3AB C8A1 D145 7368 158A 0336 C707 0AA6



signature.asc
Description: OpenPGP digital signature


Re: [PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Dmitry Stogov
yes. like it was proposed at
https://wiki.php.net/rfc/reflection_doccomment_annotations#list_of_methods_to_implement

Thanks. Dmitry.

On Mon, Feb 16, 2015 at 2:34 PM, Cesar Rodas ce...@rodas.me wrote:


 On 16/02/15 12:32, Dmitry Stogov wrote:

  you already have doc-block. nothing should be done in PHP core, but you
 have to parse it yourself.
  The goal of annotations is to provide standard and powerful way.
  On the other hand standard PHP expression syntax may be not enough for
 all cases.


 Agreed on that. I just thought it could be wise parse natively what is
 already out there. Anyways adapt our DocBlock annotation parsers to parse
 both (native PHP annotations and docblocks) shouldn't be that hard either.

 As far as I see annotations are supposed to be accessed through
 reflections right? Or will it do something automatically as in Python?

 Cheers,



  Thanks. Dmitry.

 On Mon, Feb 16, 2015 at 2:22 PM, Cesar Rodas ce...@rodas.me wrote:


 On 16/02/15 12:19, Dmitry Stogov wrote:
  I decided to explain the proposed annotation syntax in words to avoid
  misunderstanding
 
  annotations ::= { annotation }.
  annotation   ::= '' STRING '' | '' STRING '(' expr ')' ''.
 
  where expr is regular PHP expression.
 Why not doc-block annotations? So it can be parse/understand that is
 already there (Doctrine annotations for instance).

 
  Thanks. Dmitry.
 
 
  On Mon, Feb 16, 2015 at 2:07 PM, Dmitry Stogov dmi...@zend.com wrote:
 
  hi,
 
  During discussion of different ways of implementing Design by
 Contract
  we got an idea of using annotations.
 
  BTW: annotations are useful by their own and may be used for different
  purposes. Support for annotations was proposed long time ago:
 
  https://wiki.php.net/rfc/annotations
  https://wiki.php.net/rfc/annotations-in-docblock
  https://wiki.php.net/rfc/reflection_doccomment_annotations
 
  HHVM already implemented similar concept
 
  http://docs.hhvm.com/manual/en/hack.attributes.php
 
  I made a quick and dirty PoC that shows how we may implement
 annotations
  in PHP7 and how powerful they may be :
  https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2
 
  The test there is self explainable. Of course, annotations just
 provide a
  way to add metadata, but doesn't define attribute names or the ways
 they
  are going to be used. Only Reflection API to read.
 
  There are still a lot of technical problems that have to be solved.
  Right now, we just need to answer a question - if we like this in PHP7?
  Thought and opinions are welcome...
 
  Thanks. Dmitry.
 

  --
 César D. Rodas
 Open Source developer
 +595-983-161124
 PGP: F9ED A265 A3AB C8A1 D145 7368 158A 0336 C707 0AA6




 --
 César D. Rodas
 Open Source developer
 +595-983-161124
 PGP: F9ED A265 A3AB C8A1 D145 7368 158A 0336 C707 0AA6




[PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Alexander Lisachenko
2015-02-16 14:19 GMT+03:00 Dmitry Stogov dmi...@zend.com:

 annotations ::= { annotation }.
 annotation   ::= '' STRING '' | '' STRING '(' expr ')' ''.

 where expr is regular PHP expression.



Hello!

Really like this syntax, actually you steal my thoughts )) I want to call
this metadata, not an annotations. Just key-value storage for any top-level
elements (namespaces, classes, functions, methods, properties, etc).

Value can by anything, acceptable by PHP parser, then it will be possible
to provide an API to get this AST node as-is and to add a logic layer on
top of this. (I'm still waiting for the RFC karma)

For annotations, it should be possible to use ClassName::class
constant. Additionally, nested metadata should be supported.

Thanks!


[PHP-DEV] Re: Annotations in PHP7

2015-02-16 Thread Nikita Popov
On Mon, Feb 16, 2015 at 12:07 PM, Dmitry Stogov dmi...@zend.com wrote:

 hi,

 During discussion of different ways of implementing Design by Contract
 we got an idea of using annotations.

 BTW: annotations are useful by their own and may be used for different
 purposes. Support for annotations was proposed long time ago:

 https://wiki.php.net/rfc/annotations
 https://wiki.php.net/rfc/annotations-in-docblock
 https://wiki.php.net/rfc/reflection_doccomment_annotations

 HHVM already implemented similar concept

 http://docs.hhvm.com/manual/en/hack.attributes.php

 I made a quick and dirty PoC that shows how we may implement annotations
 in PHP7 and how powerful they may be :
 https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2

 The test there is self explainable. Of course, annotations just provide a
 way to add metadata, but doesn't define attribute names or the ways they
 are going to be used. Only Reflection API to read.

 There are still a lot of technical problems that have to be solved.
 Right now, we just need to answer a question - if we like this in PHP7?
 Thought and opinions are welcome...

 Thanks. Dmitry.


Hi Dmitry!

I think this is a great idea, but we should postpone it to PHP 7.1.
Especially if you want to make this AST based (which would require both
stabilizing the AST we return for expressions and having APIs to do codegen
based on the AST) it will require a lot of work both for design and
implementation. I don't think it's realistic to include a high-quality
implementation in PHP 7.

As this does not have any BC concerns that I can see, I think it would be
safer to move this to PHP 7.1, when we will have more time to carefully
design this.

Nikita