Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82890 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39118 invoked from network); 16 Feb 2015 21:15:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Feb 2015 21:15:39 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.179 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.179 mail-vc0-f179.google.com Received: from [209.85.220.179] ([209.85.220.179:62222] helo=mail-vc0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/50-36518-7FD52E45 for ; Mon, 16 Feb 2015 16:15:36 -0500 Received: by mail-vc0-f179.google.com with SMTP id hy4so11363485vcb.10 for ; Mon, 16 Feb 2015 13:15:33 -0800 (PST) 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-type; bh=8rpPvCzZGwyOlCjburaLy4oR5yeUYYzejM8xuwonreY=; b=l0ijQO7vc6EX2oyMUrGVBVUF7HGp5w6XsPgIbYD/py+Kr54N1RldYp38YwqfHES9t1 JbZA8s9QNzExiFL2FBt85tCgPMuJYAKwXCF9H2BPyG9PSDrIce5xtmTYP1QbRTDLrut8 XEta2t43gPYWSZTDzF9lqOdEOBXuZPqKUuhMazyBxvuoEtJBMVRqZax2yg8XYKxWgO/X v5VUjwvVp3a64GTWLVR2VM1R8aMZGRFAceiqtVrRsAjIblnnOKh8l2l5i2jmaMaAo7Mn 2ojaK+MPBD55NSSbFLE5KON/92lFVIV4xelDJJn3AXdjyLIgQQRmp5edNI8cVcirEgj6 OfjQ== X-Gm-Message-State: ALoCoQl/evDFI4geOpw0kUe8gQKv6eqV3OILRgYuua+oq72KbylYYunrADdf3KJkQIfUqXHwZR7Ay84Gxw5k7huBInoNjY0eSGyUjEkPFlQPoFqVIhXfPlU9W8IUWVyty6dowqDuC1N9L49ZgEF0ObiLGRfc3vQUJg== MIME-Version: 1.0 X-Received: by 10.52.99.230 with SMTP id et6mr1331727vdb.65.1424121333157; Mon, 16 Feb 2015 13:15:33 -0800 (PST) Received: by 10.52.74.73 with HTTP; Mon, 16 Feb 2015 13:15:33 -0800 (PST) In-Reply-To: References: Date: Tue, 17 Feb 2015 01:15:33 +0400 Message-ID: To: Nikita Popov Cc: Benjamin Eberlei , PHP Internals , Guilherme Blanco , Pierrick CHARRON , Alexander Lisachenko , Pierre Joye , Zeev Suraski , Andi Gutmans , Joe Watkins , Yasuo Ohgaki , Sebastian Bergmann , Stanislav Malyshev , Rasmus Lerdorf Content-Type: multipart/alternative; boundary=20cf3071c7c02e289a050f3b16d0 Subject: Re: [PHP-DEV] Annotations in PHP7 From: dmitry@zend.com (Dmitry Stogov) --20cf3071c7c02e289a050f3b16d0 Content-Type: text/plain; charset=UTF-8 Hi Nikita, On Tue, Feb 17, 2015 at 12:07 AM, Nikita Popov wrote: > On Mon, Feb 16, 2015 at 10:02 PM, Dmitry Stogov wrote: > >> >> >> On Mon, Feb 16, 2015 at 11:05 PM, Benjamin Eberlei >> wrote: >> >>> >>> >>> On Mon, Feb 16, 2015 at 12:07 PM, Dmitry Stogov 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 >>> >>> >>> How about not exposing the AST, and then the userland can pass context >>> to a method $reflection->getAnnotation($name, $context); >>> >>> https://gist.github.com/beberlei/0dc36d4412b8e3454912 >>> >>> That way AST is not exposed to userland. >>> >> >> Your example handles just particular use-case. >> I would like to provide a general solution. >> >> Thanks. Dmitry. >> > > Could you provide some more info on how you would imagine this to be used > for the DbC use case? As far as I see, this would require injecting code > into the method body based on the annotations. Does that mean that > annotations handlers will get the chance to modify the AST of the method > itself during compilation? Or how is this supposed to be realized? > In general, it must be possible to plug into compilation process using zend_ast_process() callback and modify function AST, inserting constraints validation in proper places. But for now, I'm thinking only about metadata syntax and representation. I just showed, how it can be used to represent DbC constraints. I don't think we need user-level interface to modify AST. Thanks. Dmitry. > > Nikita > --20cf3071c7c02e289a050f3b16d0--