Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93384 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30339 invoked from network); 17 May 2016 17:47:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 May 2016 17:47:10 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.218.51 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.218.51 mail-oi0-f51.google.com Received: from [209.85.218.51] ([209.85.218.51:35687] helo=mail-oi0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B8/43-11000-D195B375 for ; Tue, 17 May 2016 13:47:09 -0400 Received: by mail-oi0-f51.google.com with SMTP id x19so37120734oix.2 for ; Tue, 17 May 2016 10:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-transfer-encoding; bh=3hvdN2CfnGV87pjpFQtOuWVETA7gChdsnRArKvkSCDI=; b=SlyMeP0qpBKdbqtARehAhRzXXBPyIoPW+pf94YXtHtPEDcS6GJbnEonXcp+qlONDWy 7WJ65Y41WHG55MUOfrTYH6oNs5MCNTQ4Sc6L1CFb0uPTZdG768Zo44qBww3g5dorWeEj wLWYIjH2yi26ODPKHU6LznwPQoZcMFWMMsKZS70uVlQ8VTHeAWkiRwWU8/vqgo/PcYzv WEltgr+jVDAtCe9i/hB3jTH4Q0WFwdBVH7cIPpdNXQSKLM+tVBPP69DNDiIsfM3PIu8/ sgTgyV459i1TzE+42n26bkACy8664lez0S6JQiOykmM4nzuLy8AnpKPTs7G/+rwpZJGh MQ2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-transfer-encoding; bh=3hvdN2CfnGV87pjpFQtOuWVETA7gChdsnRArKvkSCDI=; b=ernKniw8HrlrcFTs/gVGtvp1DUiSfzTGZSraLuTtL4BV79EF6YIc/X7IwyygdHZT96 eLIbbkVrzaxlIBGiXtkILxzslgEp3CVBxcg5mWL8F5A8CiRY8YjIMqp83xP0JJzmh+Z6 p6R+uJTV+VVI5MtlmUA015tJxhBEDb8BRP8B9B6kOYj9AlTmQGUkqRQhelD6QOWzSNf4 U7t+xUAEFIHp96b5npfmTFRpX+hSN6KZr7cdkn1zLpJh5gRa5KnOuj6ruei+Dx5Qiiug EZCHALTfLam9CiLrF9gFnXnBR8iaCLWNIacS4RdJPCE9GSW26mhhjKKm3k4EW1EpFstq RpFA== X-Gm-Message-State: AOPr4FWkk3PryUq22PBjLn/5LMIS0jf16+Gs2XuMtLvqVELmwL73nMgk7cqGdANvjKCTUeqbCj06CHNOAteDtA== MIME-Version: 1.0 X-Received: by 10.157.46.90 with SMTP id c26mr1652456otd.121.1463507226575; Tue, 17 May 2016 10:47:06 -0700 (PDT) Received: by 10.157.44.214 with HTTP; Tue, 17 May 2016 10:47:06 -0700 (PDT) In-Reply-To: References: <61e6a083-91c2-799f-9757-02f56fe184e9@gmail.com> Date: Tue, 17 May 2016 19:47:06 +0200 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Simple Annotations From: rasmus@mindplay.dk (Rasmus Schultz) > I don't really understand what closures have to do with annotations, or h= ow that relates to capturing context. The point is that, rather than trying to capture context, you can just as well ask for what you need. I'm going to use a very contrived example, because I really can't think of any real case that requires context: class User { << new Validation(function ($value) { return false !=3D=3D filter_var($value, FILTER_VALIDATE_EMAIL); }) >> public $email; } Like I said, extremely contrived - in practice, you wouldn't need to attach functionality in that way. > An example from the other thread of a context-bound annotation would be i= mplementing validation like this You're not annotating the function - this is just a round-about way of annotating the argument. You would do that directly, like this: function foo( << ValidateRange(0, 100) >> int $percentage ) { ... } > 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. Probably not - what happens with what is today "nested annotations" then? Or will you make an exception for those too? The problem is, you're just reinventing a subset of the programming language, and I'm sure you can keep expanding on that indefinitely. What for? Just use the facilities already defined by the language. This fear of any feature that lets you do "evil" is incomprehensible to me. Most features of almost any programming language can be used for "evil". IMO, the real question is whether a feature accomplishes what you want. If you insist on something that also prevents things you don't want, you're bound to end up with something a lot more complex that fits into the language a lot less naturally... On Tue, May 17, 2016 at 5:28 PM, Rowan Collins wr= ote: > 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 n= ot > sure what it is you're asking for an example of. I don't really understan= d > what closures have to do with annotations, or how that relates to capturi= ng > context. > > An example from the other thread of a context-bound annotation would be > implementing validation like this: > > <> > function foo(int $percentage) > > > This would appear to be unsupported as such by your proposal, so you woul= d > instead just have to use strings to represent how it needed to be accesse= d: > > <> > > 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, bu= t > 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 fo= r > 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 >