Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78883 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33530 invoked from network); 12 Nov 2014 17:03:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Nov 2014 17:03:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:39680] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 67/70-30822-4F293645 for ; Wed, 12 Nov 2014 12:03:49 -0500 Received: (qmail 2851 invoked from network); 12 Nov 2014 18:03:45 +0100 Received: from 77.119.129.213.wireless.dyn.drei.com (HELO RoLaptop) (77.119.129.213) by ns73.kreativmedia.ch with ESMTPSA (AES256-SHA encrypted, authenticated); 12 Nov 2014 18:03:45 +0100 To: "'Rowan Collins'" , 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> <54638904.20605 @gmail.com> In-Reply-To: <54638904.20605@gmail.com> Date: Wed, 12 Nov 2014 18:03:41 +0100 Message-ID: <004201cffe9a$9dcbc6b0$d9635410$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQL8h6e288lb17uc2KnFqlPZfuXAVgERZX1bAMnT88ABcFmHWwFFMKX2Aon6cWIAi+qDmQKRtAq1AizEYZgBCr5qZwG10vVkAfUjonICT9yctQH4+NhbAfa0jr0BvYhckwDNV54UAkezwQ0BwSU7FZkUqrLQ Content-Language: de-ch Subject: AW: [PHP-DEV] Annotation PHP 7 From: php@tutteli.ch ("Robert Stoll") > -----Urspr=C3=BCngliche Nachricht----- > Von: Rowan Collins [mailto:rowan.collins@gmail.com] > Gesendet: Mittwoch, 12. November 2014 17:21 > An: internals@lists.php.net > Betreff: Re: [PHP-DEV] Annotation PHP 7 >=20 > 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 =3D> []] > > [Table::class =3D> ['name' =3D> 'foo_table']] class Foo { > > [Id::class =3D> []] > > [GeneratedValue::class =3D> [GeneratedValue::UUID]] > > [Column::class =3D> ['name' =3D> 'bar_column', 'type' =3D> = '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. >=20 > 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. >=20 > Specifically, a class annotation might look like this: >=20 > ['Blah\\Annotation\\Table' =3D> ['name' =3D> 'foo_table']] class Foo { = } >=20 > But add a single semi-colon, and you have valid PHP code > [http://3v4l.org/inkul]: >=20 > ['Blah\\Annotation\\Table' =3D> ['name' =3D> 'foo_table']]; class Foo = { } >=20 > 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). >=20 > The same reasoning rules out simple uses of @ as the prefix, because = this is also valid code [http://3v4l.org/TCBbC]: >=20 > @Blah\Annotation\Table( ['name' =3D> 'foo_table'] ); class Foo { } >=20 > Amusingly, the @ suppresses the non-existent function error, making = this look almost like it "worked". >=20 > 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. >=20 > Regards, > -- > Rowan Collins > [IMSoP] >=20 > -- > PHP Internals - PHP Runtime Development Mailing List To unsubscribe, = visit: http://www.php.net/unsub.php We could use something like the following. The : after @ makes it = unambiguous @:['Blah\\Annotation\\Table' =3D> ['name' =3D> 'foo_table']] class Foo{} or @:Blah\Annotation\Table( ['name' =3D> 'foo_table'] ) class Foo { } Just as an idea