On Tue, Jun 9, 2020 at 6:57 PM Theodore Brown <theodor...@outlook.com>
wrote:

> Hi Benjamin,
>
> On Tue, June 9, 2020 at 6:55 AM Benjamin Eberlei wrote:
>
> > Larry's suggestion about `#[Attr]` makes an important argument about
> > allowing to declare attributes in code in PHP 7 in a forward compatible
> > way that has not been brought up before.
> >
> > ```php
> > /** @ORM\Entity */
> > #[ORM\Entity]
> > class User {}
> > ```
> >
> > This code would work on PHP 7 and 8.
>
> That's an interesting argument. After thinking about it more, though,
> I'm not sure I understand what the benefit would be. The docblock
> annotation needed for PHP 7 is *already* forward compatible with PHP 8.
> So wouldn't this just be duplicating the attribute and opening the
> possibility for them to be out of sync for no benefit?
>
> Rather than duplicating attributes, wouldn't libraries simply stick
> with docblock annotations until they need to depend on other PHP 8
> features anyway (e.g. union types), and then switch completely to the
> native attribute syntax?
>
> Furthermore, even if there was some benefit to having an attribute in
> both docblock and native syntaxes, it seems like this is a very short
> term concern. In a few years once libraries are depending on other
> PHP 8 features, will this even matter anymore? So I'm really not
> convinced that this forward compatibility argument should influence
> the syntax choice.
>
> > The `#[]` syntax would have about equally low breaking potential as `@@`.
>
> Is this really the case? There's no benefit to adding extra suppression
> operators, but I have seen code in the wild using hash comments starting
> with an opening bracket (e.g. to comment out an array, or for making
> checkboxes like `#[x] Some comment here`).
>
> > As such, instead of going through each alternative syntax one by one,
> > with with each having a 2/3 requirement to overthrow the old one,
> > I would be open to restart the secondary vote on Attributes syntax
> > with `<<>>` (status quo), `@@` and `#[]` using the same ranked voting
> > algorithm that was used for the PHP 8 RM vote.
>
> I'm certainly open to holding a three-way ranked choice vote like
> this, if others are okay with it.
>
> > I would take on the work to write about the third syntax alternative
> > then. The VoteRFC could just link to the three individual RFCs where
> > each discusses their syntax.
>
> I added a section to the Shorter Attribute Syntax RFC discussing the
> pros and cons of the `#[]` syntax. Let me know if you feel it isn't
> worded fairly. I think it would be preferable to have the syntax
> choices and voting options presented in one document rather than
> spread out in different places if possible.
>
> Best regards,
> Theodore
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Hey,

How about #@Attribute as a middle ground between #[Attribute] and
@@Attribute
Shorter as there is no end token and maybe directly compatible with old
style docblock doctrine annotations.

It's true that the advantage of compatibility fades away for the #-starting
attributes when you think about having it inline as it would consider the
rest of the line as a comment
but I still think it should be evaluated, considering the current options.

Alex

Reply via email to