Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78725 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50953 invoked from network); 5 Nov 2014 16:07:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Nov 2014 16:07:44 -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 209.85.212.170 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 209.85.212.170 mail-wi0-f170.google.com Received: from [209.85.212.170] ([209.85.212.170:35002] helo=mail-wi0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A9/00-50436-E4B4A545 for ; Wed, 05 Nov 2014 11:07:44 -0500 Received: by mail-wi0-f170.google.com with SMTP id r20so449889wiv.1 for ; Wed, 05 Nov 2014 08:07:39 -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=oRVcjlWXV2KUdDp9Y2fHt2lzF4bUOfWFCh5Mx747OMA=; b=RHziDAp5F6c1sS/y/0H23Ewf6pn838pclgFweY1JvfzzMsk2+DuE5RDQf6PVvYiDzK HsOzJ9M4GlNaiUHjs3H3qEe8PkM5Cb2qftSN6tuV5jS9GXN6pyp6KI6SUtpMChusPmtO hSgVM+d902I/1uwyfeCb0xdHNf0Py+P6Fxugs/avdTvv7opXmvfINMepnfcfpt/sca8X GtwSwtjWVKfLxb5OJgo4HvJWhy5p1nUbKfRNaFXX2XvZJKgqcOCyGgnvKOSIHrJDaBTg qUcAvV6ghQt9JQWivbx0rrszinxzgCI3CevHWh+nuAdpyNiCN9iZ9HXVwDcxSZZI02MM zXyw== X-Gm-Message-State: ALoCoQkkNx3fLst3oYONAYpfR9PhI/P1JD+DIpJjg+y7uCQ+bTWtrWJspxXD4GQVHx/lnkXj8Pj+ MIME-Version: 1.0 X-Received: by 10.180.14.226 with SMTP id s2mr6825053wic.61.1415203658038; Wed, 05 Nov 2014 08:07:38 -0800 (PST) Received: by 10.194.240.137 with HTTP; Wed, 5 Nov 2014 08:07:37 -0800 (PST) X-Originating-IP: [77.180.242.185] In-Reply-To: References: <5457AF2F.90808@php.net> <5457BDB7.8070701@garfieldtech.com> <54589A8D.3020607@sugarcrm.com> <1C3F4FA3-ABD5-4F6F-A898-F63AC1C723D5@ajf.me> <54591A76.8070302@sugarcrm.com> <967E30E5-71CB-40F8-9AE2-733D327DE197@ajf.me> <545945A5.2090204@sugarcrm.com> Date: Wed, 5 Nov 2014 17:07:37 +0100 Message-ID: To: Alexander Lisachenko Cc: Marco Pivetta , "guilhermeblanco@gmail.com" , Andrea Faulds , Stas Malyshev , Pierre Joye , Levi Morrison , PHP internals , Larry Garfield Content-Type: multipart/alternative; boundary=f46d04138c9f52973b05071ec7fd Subject: Re: [PHP-DEV] Annotation PHP 7 From: kontakt@beberlei.de (Benjamin Eberlei) --f46d04138c9f52973b05071ec7fd Content-Type: text/plain; charset=UTF-8 I think keeping this just like an array definition in a property would make this both simple and flexible. You can even improve on Marcos example with a class having constants: namespace Doctrine\ORM\Mapping\Annotations; class ORM { const ENTITY = 'Doctrine\ORM\Mapping\Annotations\Entity'; // more constants here } And then use it like: use Doctrine\ORM\Mapping\Annotations\ORM; [ORM::ENTITY => ["key" => "value"]] class Article { } This would allow projects to namespace their annotations without much hassle. But it also allows people to disregard this and just write simple strings as keys with the risk of clashes with third parties. greetings Benjamin On Wed, Nov 5, 2014 at 4:15 PM, Alexander Lisachenko < lisachenko.it@gmail.com> wrote: > > 2014-11-05 17:02 GMT+03:00 Marco Pivetta : > >> For example, this alternative approach perfectly fits the current >> doctrine/annotations use-case: >> >> use Doctrine\ORM\Mapping\Entity; >> use Doctrine\ORM\Mapping\Table; >> use Doctrine\ORM\Mapping\Id; >> use Doctrine\ORM\Mapping\GeneratedValue; >> use Doctrine\ORM\Mapping\Column; >> >> [Entity::class => []] >> [Table::class => ['name' => 'foo_table']] >> class Foo >> { >> [Id::class => []] >> [GeneratedValue::class => [GeneratedValue::UUID]] >> [Column::class => ['name' => 'bar_column', 'type' => 'string']] >> private $bar; >> } >> > > This looks great indeed for many reasons: > 1) it's a simple array > 2) it can be parsed with built-in DSL syntax for PHP, so any arbitrary > evaluations with constants can be applied transparently, e.g. > [Loggable::class => ['pointcut' => self::PREFIX . 'test' ]] > > 3) C# uses similar syntax with square brackets for annotations: > > public class Foo > { > [Display(Name="Product Number")] > [Range(0, 5000)] > public int ProductID { get; set; } > } > > However, I would like to see simple markers without nested associative > arrays, e.g just put single AnnotationName::class into brackets or specify > multiple annotations in one section: > > [Entity::class, Table::class => 'foo_table'] > class Foo > { > // ... > } > --f46d04138c9f52973b05071ec7fd--