Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64746 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24975 invoked from network); 9 Jan 2013 15:15:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Jan 2013 15:15:53 -0000 Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 209.85.212.182 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 209.85.212.182 mail-wi0-f182.google.com Received: from [209.85.212.182] ([209.85.212.182:53473] helo=mail-wi0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5A/6A-02684-7A98DE05 for ; Wed, 09 Jan 2013 10:15:52 -0500 Received: by mail-wi0-f182.google.com with SMTP id hn14so585912wib.9 for ; Wed, 09 Jan 2013 07:15:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=J92KszZbC0rP/t74yt2BtFPSYzLkW0Kzt+KWUEAKptY=; b=DIgIuVVjICEVATt3/X2svRwpyAPgkqh7EsKg0u43FXMAAi2VxIzNgVU9X1M0hVP0Ck m6fTRn6qOSb8NLT9atPOe8Pzi0YmE+4FxlLfkAfuLqNksxIr7wf6VxLDWEondG0huh7B CXnUT6VdtEUgFDUz4id8x8GPEVVAmL2xd2ZZ1pYC02neCuw7zfMBfIRLpxQWEb3D60vA KJk9DsHWNItFP1KE5F1HaKlKgvZcY9HhonMDuayKOc2JOkhfbZ4fTxe6d1Ft0Q1IkTq7 W9k0T7DKZqX+PitxFHG3CNBQDP1gQTKRqL1fapa41P3EnAZBk7k+KKdSu5TZ0ZiJhnSO Inbw== MIME-Version: 1.0 Received: by 10.180.101.99 with SMTP id ff3mr3926553wib.21.1357744547999; Wed, 09 Jan 2013 07:15:47 -0800 (PST) Received: by 10.194.59.36 with HTTP; Wed, 9 Jan 2013 07:15:47 -0800 (PST) X-Originating-IP: [77.13.202.63] In-Reply-To: References: <50EBDEEE.8070605@sugarcrm.com> Date: Wed, 9 Jan 2013 16:15:47 +0100 Message-ID: To: Derick Rethans Cc: Vladislav Veselinov , Pierrick Charron , Stas Malyshev , Rasmus Schultz , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f46d044280e87aafad04d2dc8977 X-Gm-Message-State: ALoCoQnk8fTkD4vWwK1DaXMrP17ao9Bqln/DKmevC4ZpIYZsTyosbB0if7ILOuyd4x0lEzKMFsIr Subject: Re: [PHP-DEV] [RFC] Reflection annotations reader From: kontakt@beberlei.de (Benjamin Eberlei) --f46d044280e87aafad04d2dc8977 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jan 9, 2013 at 3:48 PM, Benjamin Eberlei wrote: > On Wed, Jan 9, 2013 at 1:42 PM, Derick Rethans wrote: > >> Please, no top posting!!! >> >> On Wed, 9 Jan 2013, Vladislav Veselinov wrote: >> >> > Taken from the Doctrine documentation: >> > >> > > > class User >> > { >> > //... >> > /** >> > * @ManyToMany(targetEntity="Group") >> > * @JoinTable(name="User_Group", >> > * joinColumns={@JoinColumn(name="User_id", >> referencedColumnName="id")}, >> > * inverseJoinColumns={@JoinColumn(name="Group_id", >> referencedColumnName="id")} >> > * ) >> > */ >> > private $groups; >> > //... >> > } >> > >> > Not that I'm a fan of it, but it provides a valid usecase. I'm sure >> > there are more. >> >> Maybe valid, but sticking this into core-syntax seems mental. >> > > The Doctrine Syntax is verbose, because that is necessary to make up for > the missing compile time support in the language. > The core could easily offer a "simpler" language or one that looks more > like PHP code (array syntax). > > If you take a look at annotations by starting with PHP code, instead of > docblocks and the syntax optimized for that use-case you can end up with > something much simpler, see: > > The most simple type of annotations is attaching metadata to a class, > method, function, property. In Clojure this is actually done like this at > runtime setting a hashmap to any structure. > In PHP that would be something like: > > function foo() {} > > $refl = new ReflectionFunction('foo'); > $refl->setMetadata(array('foo' => 'bar')); > $refl->getMetadata(); > > Doctrine Annotations do allow "retrieving" metadata for any structure, > sspecified in docblocks. For seperation we need something the Annotations > RFC defined, a new type of docblock that is executable code wrapped in for > example <> brackets, if this were just PHP code, then we'd have: > > 'bar'))> > function foo() {} > > Now the difference between this syntax, and something resembling "Docblock > Annotations" would mean that the last statement between <> is returned from > the block. With short syntax for arrays we get: > > <['foo' => 'bar']> > function foo() {} > > Now this is nothing new to learn for anybody, except that <> code for any > structure can be "executed" using $reflection->getMetadata(); > > And the crazy people (like me) could do more structured things: > > use Doctrine\ORM\Mapping AS ORM; > > <[new ORM\Entity, new ORM\Table(name="user")]> > class User {} > The last two lines are wrong, must obviously be: <[new ORM\Entity, new ORM\Table(['name'=>"user"])]> class User {} --f46d044280e87aafad04d2dc8977--