Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92682 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97199 invoked from network); 24 Apr 2016 11:36:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Apr 2016 11:36:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 74.125.82.54 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 74.125.82.54 mail-wm0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:38301] helo=mail-wm0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 11/A1-21220-8AFAC175 for ; Sun, 24 Apr 2016 07:36:09 -0400 Received: by mail-wm0-f54.google.com with SMTP id u206so87346301wme.1 for ; Sun, 24 Apr 2016 04:36:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beberlei-de.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=NDAlVRKvElVAW+BZWtMatD8vF7Rxd48srvZPsPxzS9s=; b=QQ8iJMWmCOeM9aGOd3IBDBmXd0X2XVYJiGqa3UUtBoQ0N+VfGxXTJlmaQyv96nF0n7 WVbYvAr42Z4LqoLlhOdYu7UVcOdJHzpIy5D8bJcEdXR6yDJBcVax6t9ZBkajoJqSlW+j 0YGzSJaqfu/YH61l989Y7Ge8DYaysZUPgCUKYEG9SQBxwJmT4etV0nMUaZI3627NVUS+ dIMcSEObvlCHvjD1HJuS/qNZuCYsSFFmuXz3Vhg7ycHkDFT1/vfuQZnHk+emq97T1G4/ nOfL6ZwOTwyak4zxUY0uYsJnqPgjma/XEe2ahuQkuo1WO5OM/vbk+ZnwG9/5L0g8VRTd sDyA== 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; bh=NDAlVRKvElVAW+BZWtMatD8vF7Rxd48srvZPsPxzS9s=; b=bR4jwQ/WACNLszJp6b8BQ20fhU4bCVztpyrpgC//xQCyEgZy0xDd4yoNVlVDupYroK 7MboLwHJKHumTL/JMgRnkh8X1n8btX/YY67FUkxQzq9HchFzMBAnMsocRXbJR7OpE0aW pZ6FZkBfwYMUcJnYXy+7brxZcRIYzFsqy0UA2ZAJP8gmODIoXDJFeUuS1lW0furi6g19 6EOkmoESCFurZy+SpJ3HT/6BoHZkg4CW1a5RSW8/ITWTN6A/4/00Dw3L3JNEfxVBLTya GXLYUEyFZg2ngNsqByUqHBtQ0XIjZ+MzHwaHGQA+JlbqatU0uFic6W03njCex9QmDWF+ dlWA== X-Gm-Message-State: AOPr4FWn68nL9Fte9EKAoZU1cAyHKR0wR1n8Jb1pwX/VSs7vveCkEhyzRCDVXTL5c+8k++20Hu7Lpdc+DSfh1w== MIME-Version: 1.0 X-Received: by 10.28.4.149 with SMTP id 143mr6333413wme.44.1461497765815; Sun, 24 Apr 2016 04:36:05 -0700 (PDT) Received: by 10.194.94.163 with HTTP; Sun, 24 Apr 2016 04:36:05 -0700 (PDT) X-Originating-IP: [93.129.116.46] In-Reply-To: <571C82A7.2060706@fleshgrinder.com> References: <571BA0F0.2030400@fleshgrinder.com> <571C82A7.2060706@fleshgrinder.com> Date: Sun, 24 Apr 2016 13:36:05 +0200 Message-ID: To: PHP Internals Cc: Sara Golemon , "dmitry@zend.com >> Dmitry Stogov" Content-Type: multipart/alternative; boundary=001a1141d2942c055c05313977ad Subject: Re: [PHP-DEV] [RFC] PHP Attributes From: kontakt@beberlei.de (Benjamin Eberlei) --001a1141d2942c055c05313977ad Content-Type: text/plain; charset=UTF-8 On Sun, Apr 24, 2016 at 10:24 AM, Fleshgrinder wrote: > The invariant could also be added as an additional branch to the class > instead of a method, since it would not work like a method. > > class A {} invariant {} > > function f() {} require {} ensure {} > > This would also align nicely with closures and anonymous classes, which > is kind a problematic with annotations. > You are way off topic with this imho. > > $A = new class {} invariant {}; > > $f = function () {} require {} ensure {}; > > The only thing that remains that might be of interest to both is > `@throws` but that was not discussed at all as of yet. > > use Ns\SomeException; > > @throws SomeException > function f() { > > } > > This is at least how one would expect it to work and it is something > that should be covered by annotations and not as part of the language. > The ABNF should account for that: > > ANNOTATION = "@" NAME [ " " VALUE ] > NAME = STRING > VALUE = QUOTED-STRING / PHP-REFERENCE / EXPRESSION > QUOTED-STRING = ( "'" / DQUOTE ) STRING ( "'" / DQUOTE ) > EXPRESSION = PHP-CODE ";" > Where PHP references are any of the already possible ones: > > use F\Q\C\N; > > @annotation \F\Q\C\N > @annotation N > @annotation \F\Q\C\N::CONSTANT > @annotation N::CONSTANT > @annotation \F\Q\C\N::function() > @annotation N::function() > @annotation \F\Q\C\N::$variable > @annotation N::$variable > > I also though some more about function support for annotations and this > would actually be a nice thing for userland. > > annotation deprecated(Reflection $element, string $message = '') { > @trigger_error($message, E_USER_DEPRECATED); > } > > @deprecated('because') > function x() {} > > @deprecated > function y() {} > Attributes as proposed by Dimitry are not executing functions, they are only metadata that can be retrieved through reflection API. I think a python style decorator approach that you propose here, executing functions is not what the different pro-annotations, pro-attributes or pro-DesignByContract fractions want/need. You are proposing something along the lines of AOP, which is an entirely different beast in my opinion. > This would allow users to implement simple and easy reactive annotations > in userland. Even if this could or should be an extension of the feature > in the future, it should be thought about know. Simply because the > brackets make sense if such a feature is to be implemented. ;) > > -- > Richard "Fleshgrinder" Fussenegger > > --001a1141d2942c055c05313977ad--