Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94307 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75144 invoked from network); 28 Jun 2016 17:04:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2016 17:04:50 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.49 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.220.49 mail-pa0-f49.google.com Received: from [209.85.220.49] ([209.85.220.49:34321] helo=mail-pa0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E1/45-41838-13EA2775 for ; Tue, 28 Jun 2016 13:04:49 -0400 Received: by mail-pa0-f49.google.com with SMTP id bz2so8198174pad.1 for ; Tue, 28 Jun 2016 10:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=bHDCehIb7daDvtINTi9G3UghLReVil5vn7hzwT9E49k=; b=DO8pbMeUHDbL4IournvY9v8PgaikxaWqK/bE8gYlbSVH4lxrz/d6SDASVAUHAHYYlW 9GOPAy3dVMwmRSNzv2VHo859OJE0poOfAgwHNK2OUD5S7qp8HNRVcxgx1cLfqAJk5YEf xVnRUa4jNH58pQYNL78JcXDktGLcVFkesa4OyMBXZhIQPZZR+dVB5FBxtD6X2gYDK9Zn +1HotiwptgukjlxSi+zyKPFH6NjvoEio9XjxxI5NYGwbOyw8WUO8E893lIfdit1Ngs4r WM6dt0zLUzL6v2/nzq4kxrQ4CysaXB6IC2HMjU8NhdVqB7hxGHwCZUHpPxIUnDJ9e7zP GDIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=bHDCehIb7daDvtINTi9G3UghLReVil5vn7hzwT9E49k=; b=KC08EkfCsWGgw2tWrMJMgnPFnzsv8YzElq2kgraYlwUEgtTQETH0a0vjmmb3fZKY3F QYokHkZqn75AldTSyDw215hm2mSnIiS5ENOQbuKSTheLfxEBQVPBkzw2nmKgC5AmMonq vRDYl0XW2HuWQGhvAPrPeDXP5eMgtQy4EfFLyD6ZDVngSr80xwexhOHw4kqkD4tEwGWr aaqIqOqNZQH5WaFti4+4xXDqzo93PpB7o4y8VX2rY7IFzKpSNFKE4m2WVAhM9LHvWVxZ NTAb2f97q2XzSvtADfuHuANmrTCfZd7S6dgk7e5sgeLD4MZdbeFQhMlI5tF23vnerCyS 3PMQ== X-Gm-Message-State: ALyK8tKDASvc/v0HQjVKV63/mdsk8QVaLgixqXRDTQdFc4o8Q66PB5TcUensUXwUiBlnAQ== X-Received: by 10.66.97.104 with SMTP id dz8mr3606790pab.22.1467133486607; Tue, 28 Jun 2016 10:04:46 -0700 (PDT) Received: from [192.168.0.98] ([93.188.182.58]) by smtp.gmail.com with ESMTPSA id j5sm807709pfj.71.2016.06.28.10.04.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jun 2016 10:04:45 -0700 (PDT) To: internals@lists.php.net References: <211db59e-9c22-6df4-1f72-66ebbc5095bd@fleshgrinder.com> Message-ID: <0fca0a81-fafb-58ea-9cc6-99372dc9a99f@gmail.com> Date: Tue, 28 Jun 2016 18:03:05 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Simple Annotations From: rowan.collins@gmail.com (Rowan Collins) Hi Rasmus, I think you may be onto something here... :) On 28/06/2016 17:31, Rasmus Schultz wrote: > The UnknownAnnotation object has three properties: class-name, > method-name ("__construct" if constructor was used) and the list of > arguments. I'm not sure we need an extra UnknownAnnotation class. It seems like all of that information could be available on the ReflectionAnnotation object, so you can get it without the class being available if you want to. If the idea is to lazily-evaluate the arguments to the annotation, that could be handled by storing the AST and only evaluating them when you call either $annotation->getInstance() or $annotation->getArguments(): use MyAnnotations\FooAnnotation as Foo; // Class alias resolved at compile time as normal << Foo(time()) >> class A {} $class_reflection = new ReflectionClass('A'); $annotations = $class_reflection->getAnnotations(); foreach ($annotations as $annotation) { if ( $annotation->getClassName() == 'MyAnnotations\\FooAnnotation' ) { var_dump( $annotation->getArguments() ); // `time()` evaluated here var_dump( $annotation->getInstance() ); // `new MyAnnotations\FooAnnotation(time())` evaluated here } } It's not the responsibility of the ReflectionAnnotation class to worry about calling the autoloader, issuing errors, etc, it should just delegate that to the engine like any other constructor call. There's no need for an extra $annotation->classExists() method, either, because you can just say "class_exists($annotation->getClassName())". Interestingly, this same delayed evaluation of arguments opens us up to include direct access to the AST as some (Nikita?) have asked for: // Constructor argument can be any valid expression, // however nonsensical it would be to evaluate it directly << Pre($a >= 42) >> function foo($a) {} $r = new ReflectionFunction('foo'); $annotations = $r->getAnnotations(); foreach ( $annotations as $annotation ) { if ( $annotation->getClassName() == 'Pre' ) { $ast = $annotation->getArgumentAST(); // Now we can do funky things with the AST, like evaluating it in a custom context :) } } Regards, -- Rowan Collins [IMSoP]