Re: Annotations in PHP7
| From: | Pavel Kouřil | Date: | Wed, 18 Feb 2015 20:29:41 +0000 |
| Subject: | Re: Annotations in PHP7 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83115@lists.php.net to get a copy of this message | ||
On Wed, Feb 18, 2015 at 7:28 PM, guilhermeblanco@gmail.com
<guilhermeblanco@gmail.com> wrote:
> Hi Dmitry,
>
>> Are you (and Doctrine team) interested in this annotation idea?
>
> I'd say that Benjamin nailed in our possible usage:
>
> <orm(new Entity("foo"))>
> class Foo {
> }
>
> Now I do feel we need to elaborate some sort of named parameters. Doctrine
> tries to simplify a lot developer's life by using consistency in default
> mapping and only if the user wants to override default behavior he needs to
> override a given parameter. This means in a case where you're mapping a
> JoinColumn (
>
> https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Mapping/JoinColumn.php
> ),
> you may only want to specify the onDelete="CASCADE" operation instead of
> name, referencedColumnName and many other parameters.
> Trying to map this in your default parameter passing, we'd have something
> like:
>
> <orm(
> [
> new OneToOne("Address"),
> new JoinColumn(default, default, default, default, "CASCADE")
> ]
> )>
> public $address;
>
> As I said, named parameters make a lot of sense when mapping defaults.
> Now by looking at this syntax, I still think we're closer to a simple array
> implementation (ReflectionClass::getMetadata(string $name)) and having
> something like:
>
> <[
> "orm" => [
> new OneToOne("Address"),
> new JoinColumn(default, default, default, default, "CASCADE")
> ]
> ]>
> public $address;
>
>
> PS: We haven't even started on talking about overrides yet... =\
>
As a Doctrine user, I find this way worse than current state. This
syntax looks UGLY and contains a lot of useless clutter. And yeah,
adding named parameters to PHP be pretty helpful to make annotations
more readable. :(
And to what Francois said ("Anyway, I don't like the OO features
people want to add everywhere. They can get strings and inject them to
OO, but that's not the role of the annotation layer, IMHO. I
definitely prefer the KISS approach."). What's exactly wrong with
doing annotations in an object oriented manner? Both Doctrine
Annotations and C# have them as objects, and it works well. Having
annotations as just array of expressions/strings/whatever and needing
another library to parse them is not really that great "upgrade" from
current state. :(
Regards
Pavel Kouril