Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93380 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22078 invoked from network); 17 May 2016 16:22:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 May 2016 16:22:15 -0000 Authentication-Results: pb1.pair.com header.from=guilhermeblanco@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=guilhermeblanco@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.181 as permitted sender) X-PHP-List-Original-Sender: guilhermeblanco@gmail.com X-Host-Fingerprint: 209.85.223.181 mail-io0-f181.google.com Received: from [209.85.223.181] ([209.85.223.181:35909] helo=mail-io0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/E1-11000-6354B375 for ; Tue, 17 May 2016 12:22:14 -0400 Received: by mail-io0-f181.google.com with SMTP id i75so30060705ioa.3 for ; Tue, 17 May 2016 09:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=N6gkMZlmAIMrLdVfuaktEXoluFdmV/Z7RDyQkGSyn+Q=; b=ykscYNj37z3reppjqRqgg81FX5FAHD6Vl4G1hK1r7g/5mcS+hFa4t2LRiWMtK3lJa8 XwOE1U3KK6hl9RZDCRcJk79TzDYViZoyt0NMccrl/AsU1tukizs5UB9adgCPZhuEukpg C9ayvbxRFMGJJrWR+JZsTgz1XJJtIwYAo6pw3B3slIMbX6rf77VLHMR2fbnHiFiY1d7O bNO04QqqvlU7zQ7Ky8D1SWDzojXZsOXruhEPgjveBDKEGhAFd/RGVhIM/bmoQh8isX7X UovGUVfNy31TH6Rocnb+NJ9d1ui32gDa3gNuIt2EYsxuDCzjEn/ZAx/bSBsCmDGRC61p IQGQ== 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:from:date :message-id:subject:to:cc; bh=N6gkMZlmAIMrLdVfuaktEXoluFdmV/Z7RDyQkGSyn+Q=; b=KfuRjS/XCt6339BaZ44H1lcEDuvYARMEqCShzvZEcydID5aa6DJWxOvPwTFwOu0Sm9 vmsuUbxX/urvYbA6CqphhT5H+CdGeyezVipfzIJwEPnVucXvgVjs8k5fJnMKZGUYfSnS hLlvZa1eeWwMUc9yGSEPXFBcP+YVjYbl3nynyG1/OPcDusj6prEL8y3Yqg8IijdYDGHe v7zGr4/86FGT6c0XzF8z+tVXt2FqjUyly9cw3w6a09Jv5thBPN1fINym1I9/UIWcZdNk qZ1G0iTmn66Ax8RDQsws6InaE1EF8ENeebLTA199rPuhCmzgNzg+PPmRBEK7pIbUAY9r woEA== X-Gm-Message-State: AOPr4FUeluBdOL/+CluZihCXcXQH+7oUhoGR47fRAjh7XjPoSGyliVl/X+v06bhXQcJ1IHJB8VKzO2WempQddA== X-Received: by 10.107.31.146 with SMTP id f140mr1801147iof.180.1463502131688; Tue, 17 May 2016 09:22:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.70.162 with HTTP; Tue, 17 May 2016 09:21:52 -0700 (PDT) In-Reply-To: References: <61e6a083-91c2-799f-9757-02f56fe184e9@gmail.com> Date: Tue, 17 May 2016 12:21:52 -0400 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=001a1140b648b00bc805330c244e Subject: Re: [PHP-DEV] [RFC] Simple Annotations From: guilhermeblanco@gmail.com ("guilhermeblanco@gmail.com") --001a1140b648b00bc805330c244e Content-Type: text/plain; charset=UTF-8 @Rasmus: This approach is too broad, allowing situations like Marco pointed out. I'd have to vote -1 on it too if you move forward, specially if you consider things like << "How do I grab this?" >> and other weirdness. @Rowan: Annotations should be immutable by nature. Still, I would love if you can detail (in the context of your example) what should be the output in the following examples: <> function foo(int $percentage) { $reflection = new \ReflectionFunction(__FUNCTION__); var_dump($reflection->getAnnotations()); // #2 } $reflection = new \ReflectionFunction("foo"); var_dump($reflection->getAnnotations()); // #1 foo(10); When executing the code, what should I expect from #1 and #2? I can foresee that #1 should crash (?) or should it return an ast\node or what? It all sounds reasonable on #2 what everyone is heavily forcing/suggesting because of DbC, but it *only* makes sense in the context of a function call (or a bound object in case of OO members). In any other case its outcome is unpredictable. There're 2 potential approaches I can foresee with future for Annotations: 1- This one I see as a simple approach. Take the idea of Dmitry and extend to support scalars and arrays (only, no objects, no AST\Nodes). Example: << Entity(["name" => "User"]) >> Strings could be easily converted into AST\Nodes internally and DbC would be possible. Context is inferred at libraries' desire. Solution here would not have a 1-1 dependency with classes, simplifying the implementation for meta parameters such as "override", "inherit", "memoize", "jit", etc. 2- Take an OO approach and correlate 1-1 class. But before that I'd tackle object initialization first. We'd require to make this to work: new Foo() { "property" => "value" } After that, we could get back to Annotations and support a subset of PHP grammar, similar to this: << Foo { "property" => "value" } >> Why I suggest this approach, some may ask? Simple young padawans... We're already seeing people discuss about final/read-only properties, where they could only be set at constructor time. We could easily expose this possibility through scopes. The {} block would be post constructor, but still in the initialization context, allowing sets to happen for read-only properties. It's a smart solution against adding a long list of constructor arguments (and handling default values for each one) and also a nice alternative to "named parameters". However, this approach would still require a 1-1 dependency with classes, which would make "override", "inherit", "jit" a PITA, and likely empower a more robust annotation solution (like defining which class can be an annotation and what cannot, or specify annotation target, like class, method, property, etc). PS: I hate to write long emails... =( Cheers, On Tue, May 17, 2016 at 11:28 AM, Rowan Collins wrote: > 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: > > <> > 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: > > <> > > 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 > > -- Guilherme Blanco Lead Architect at E-Block --001a1140b648b00bc805330c244e--