Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78882 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28361 invoked from network); 12 Nov 2014 16:22:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Nov 2014 16:22:03 -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.212.176 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:58566] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/71-17424-92983645 for ; Wed, 12 Nov 2014 11:22:02 -0500 Received: by mail-wi0-f176.google.com with SMTP id h11so5426675wiw.9 for ; Wed, 12 Nov 2014 08:21:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=aGEHFE2IGCpAMYxdjeDQSzVQ2gJK3o8yKmcWizRuC4g=; b=xN23D65ttLzUasC6lsj5Ug3tcfQ8qUARtrlvvDe7jCSgveZfQur65ey6l3+yQp1DBg 2jpzrJ0VtS4Ys2jtocGxW5CcUc+RuB3HEdPBAsAvYbffK6Bo9iKHTz9Pwnxp7ajPcMe9 1NNYafSxze7rbHdRoDbr/cSaGk6D0fy0j9E9OoiOHhk2TVtXd9AwC+RECIV0sHlE02y1 1AEdmme1NwSPejWYQix/Ht/Ro16qdc1xUTBIJpMBspWx2SU3ximBllm9xlQmqza3XkqR nkqUBw+d3yh5kxVELTrs9jhawQ6gY2G9pB41JsdSaFhGc9HfgxZ2YeyMZXCf1+zB3O/r 3ilg== X-Received: by 10.194.61.99 with SMTP id o3mr63737330wjr.54.1415809318036; Wed, 12 Nov 2014 08:21:58 -0800 (PST) Received: from [192.168.0.139] ([62.189.198.114]) by mx.google.com with ESMTPSA id da3sm32024991wjb.12.2014.11.12.08.21.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Nov 2014 08:21:57 -0800 (PST) Message-ID: <54638904.20605@gmail.com> Date: Wed, 12 Nov 2014 16:21:24 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: internals@lists.php.net 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> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Annotation PHP 7 From: rowan.collins@gmail.com (Rowan Collins) Marco Pivetta wrote on 05/11/2014 14:02: > 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; > } > > I did nothing special here, just using plain old associative arrays and > built-in `::class` pseudo-constants: this leaves space for libraries that > do want to use annotations, but not the way doctrine/annotations does it > (calling the constructor of an annotation), and the annotations themselves > can still decide what to do with nested values. > > No autoloading is going on, no code execution, nothing: plain and simple > arrays which may as well be used for phpdocumentor as well, if needed. One problem with using *just* array syntax, without any new keyword or symbols, is that it is extremely close to being existing valid syntax. This may well cause problems in the parser, and would certainly be confusing to users. Specifically, a class annotation might look like this: ['Blah\\Annotation\\Table' => ['name' => 'foo_table']] class Foo { } But add a single semi-colon, and you have valid PHP code [http://3v4l.org/inkul]: ['Blah\\Annotation\\Table' => ['name' => 'foo_table']]; class Foo { } This works because an expression, by itself, is a valid statement, as long as it's terminated with a semi-colon, and before the "class" keyword, you are just in global execution scope (a problem many other languages don't have to worry about, because statements can't exist outside blocks). The same reasoning rules out simple uses of @ as the prefix, because this is also valid code [http://3v4l.org/TCBbC]: @Blah\Annotation\Table( ['name' => 'foo_table'] ); class Foo { } Amusingly, the @ suppresses the non-existent function error, making this look almost like it "worked". Having a single semi-colon change an annotation into a silent statement seems like an extremely bad idea. The "inside" of an annotation can look like an array or constructor call, but we need something distinct to introduce (or wrap) it, assuming we want it positioned before the "class" keyword, as in other languages. Regards, -- Rowan Collins [IMSoP]