On 17/05/2016 15:22, Rasmus Schultz wrote:
The other issue is the dependency (context) injection example - no one
seems to be able to cite an actual use-case, and if that's the case, I
should probably just remove it from the RFC entirely?
@Larry can you think of a case example in the myriad annotations
you've seen in Drupal code? :-)
Anyone else using Doctrine Annotations actually seen anyone making use
of a closure in an annotation?
Possibly nobody's responded to your call for an example because they're
not sure what it is you're asking for an example of. I don't really
understand what closures have to do with annotations, or how that
relates to capturing context.
An example from the other thread of a context-bound annotation would be
implementing validation like this:
<<ValidateRange($percentage, 0, 100)>>
function foo(int $percentage)
This would appear to be unsupported as such by your proposal, so you
would instead just have to use strings to represent how it needed to be
accessed:
<<new ValidateRangeAnnotation('$percentage', 0, 100)>>
and then have extra machinery in the reflection logic to extract the
parameters and pass them to the object, e.g.
$annotation->validate($reflected_parameters)
This might be the more sensible approach to such an annotation anyway,
but without any access to variables, I don't really understand the value
of evaluating an expression for the annotation, just to get a constant
value that is cached by the Reflection infrastructure.
If the expression would have to be made up entirely of constants anyway,
might the same "constant expressions" used in class const definitions be
a better fit than "any valid PHP expression" - plus a specific exception
for creating objects out of those constant expressions.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php