Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93067 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98845 invoked from network); 4 May 2016 12:20:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 May 2016 12:20:28 -0000 Authentication-Results: pb1.pair.com header.from=jesseschalken@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jesseschalken@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.179 as permitted sender) X-PHP-List-Original-Sender: jesseschalken@gmail.com X-Host-Fingerprint: 209.85.213.179 mail-ig0-f179.google.com Received: from [209.85.213.179] ([209.85.213.179:35160] helo=mail-ig0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 06/53-08540-B09E9275 for ; Wed, 04 May 2016 08:20:27 -0400 Received: by mail-ig0-f179.google.com with SMTP id bi2so145349356igb.0 for ; Wed, 04 May 2016 05:20:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc; bh=PtnPMC7/DlT2HJEARV7SRFp8iSuG/gEsVuhCQzlE1bI=; b=CEXZo/3glcuTcYOg7fOfdZXdf+KoMpMR08RWQJ0wfa0YlUOhHktSkB9LbvoPKwQ9CW ydM9Im0hxKj6OeRufohkQ4u9daTaZDpT3fPuazt1zVdUKXfS6hAPnL+6pUJk662DREHE JWGzTwHI/JakRe5msoGoJGro9w8Ynq8qVw5eg9FNLYSDIEFpx+IDlZjPe7AjjVyJk2V5 9KdGcF7Wkfq/5GbmOiBjjUFJs0uiT2LR0uy08dy3gJeGRuiC7I76X/XP00hRR67ljOQZ 8boOJlaYh66yxQoQQEVJf9+fG7adHe0tND10vBIONdXuau9Ad2vieGEmVPwP4i1oiaZQ rZGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc; bh=PtnPMC7/DlT2HJEARV7SRFp8iSuG/gEsVuhCQzlE1bI=; b=bOWFhHFzyVEgTH58OqeBSbGa5seFXoJmE9bV9TYM3a+OV/MU9NPxVmBUKe1z887Oz5 ROHqrRxiJj7D5O3wUriQ7Get6YtLhiwZYBjVCKg4ua4K+CRAzwp6CKiCWk3MEWCQo0N5 y0rpWSvGHfwhz8VA+vCCV794r6EFZnI3KgLzVisd+LbMoE1aTb3pRu5cV1UCypMUJ5ID YJizwAKak0CvMmJbOxBNTtDngZEJwCEFTrcbMGw9K2LALJP/Y9ts9RTYJ4scLzimD1Rk Mc6ZRLLPWuwG7xGhdtnSWD6rYa2DS8Tcv/1u/Gp+VdhoJpmIHI12xpHKjG0udek206cZ poTA== X-Gm-Message-State: AOPr4FWd0LqmzivLu5sb4zTogOivt/ydTVFNTPkFSO9zsV4PiT8kc5lc4J7wkPuRc/Qq9WhOIK3Y7ABgKY9tpA== MIME-Version: 1.0 X-Received: by 10.50.160.129 with SMTP id xk1mr10604444igb.55.1462364423578; Wed, 04 May 2016 05:20:23 -0700 (PDT) Sender: jesseschalken@gmail.com Received: by 10.79.139.3 with HTTP; Wed, 4 May 2016 05:20:23 -0700 (PDT) In-Reply-To: <5723F2AE.2020806@garfieldtech.com> References: <5723F2AE.2020806@garfieldtech.com> Date: Wed, 4 May 2016 22:20:23 +1000 X-Google-Sender-Auth: P4kCjINPNouih2-snyIsFn5FAH8 Message-ID: To: Larry Garfield Cc: PHP internals Content-Type: multipart/alternative; boundary=14dae9340bd7fff0650532033ff9 Subject: Re: [PHP-DEV] Attributes/Annotations Case Study: Drupal From: me@jesseschalken.com (Jesse Schalken) --14dae9340bd7fff0650532033ff9 Content-Type: text/plain; charset=UTF-8 On Sat, Apr 30, 2016 at 9:47 AM, Larry Garfield wrote: > 3) Some way to provide a data definition for the annotation that can be > checked at compile time. This could be classes, a la Doctrine. It could be > a new Annotation type as others have suggested. It could be something > else, akin to a struct like Liz Smith keeps toying with. I'm flexible > here. But some way to provide a data definition for the annotation that is > more robust than "you get an AST for an associative array that you can eval > to an array yourself, good luck" is, I believe, mandatory for these to be > successful for more than the most trivial use cases. If that data > definition is a class or class-like type, that also resolves the namespace > question very easily. > > I would love it if annotations were just classes with public properties, and the annotation shorthand for instantiating and setting properties was generally avaliable. At the moment if you wish to instantiate an object and set some public properties, you have to use a temporary variable $album = new Album(); $album->name = "Albumius"; $album->artist = "Artistus"; $album->year = 2013; return $album; or define setters for all the properties so you can chain them return (new Album()) ->setName("Albumius") ->setArtist("Artistus") ->setYear(2013); or forego the benefits of classes and use an array return [ 'name' => "Albumius", 'artist' => "Artistus", 'year' => 2013, ]; C# has an "instantiate-and-set-properties" shorthand like this, which would be great to have in PHP: return new Album() { name = "Albumius", artist = "Artistus", year = 2013, }; and if you drop the "new" (and constructor parens are already optional) you've got a pretty good annotation syntax right there. <> <> <> So the annotation syntax could just be class instantiation without the "new". (maybe there should be a $ before the property names, not sure) --14dae9340bd7fff0650532033ff9--