Hey Benjamin,
I haven't really followed the discussion, so sorry if anything I'm
writing has already been discussed.
Attributes / annotations are one of the two things I currently miss
most in PHP (the other being generics), so thanks for the work on
that!
There are a few points that seem odd to me, I'll start with the "Php" prefix:
```php
<?php
namespace My\Attributes;
use PhpAttribute;
<<PhpAttribute>>
class SingleArgument
{
public $value;
public function __construct(string $value)
{
$this->value = $value;
}
}
```
I think this should be <<Attribute>> instead, if we go with that
syntax. However, I'd even propose another syntax, as attributes aren't
ordinary classes, I'm not sure whether they should be instantiatable
from userland and / or be able to use inheritance, especially as
constructors in PHP aren't subject to variance rules. I guess the
INSTANCE_OF filter also changes whether the attributes are autoloaded
or not?
I expect annotations to be readonly, which classes as outlined in the
RFC cannot currently enforce in PHP. A syntax similar to interfaces
might be appropriate, I'm not sure whether that has been discussed:
```php
<?php
namespace My\Attributes;
attribute SingleArgument
{
public function value(): string;
}
```
Such a Java-like syntax would unfortunately only work with some kind
of named parameters.
Finally, the naming of "getAsObject" should IMO be improved,
especially if I read the RFC correctly and autoloading and constructor
invocation is performed by this method. I think "createObject" or
"toObject" might be better names.
In summary, I'd probably vote "no" on the current proposal, even if
it's one of the most missed features, because I think we can do
better, and there's only one chance.
Best,
Niklas
Am Fr., 17. Apr. 2020 um 12:49 Uhr schrieb Benjamin Eberlei
<[email protected]>:
>
> As there has only been minimal new discussion after the last changes to the
> RFC I wanted to give a heads up that I will open the vote on Monday
> afternoon.
>
> If you have further remarks or questions about the RFC, please let me know.
>
> On Mon, Mar 9, 2020 at 3:42 PM Benjamin Eberlei <[email protected]> wrote:
>
> > Hi all,
> >
> > I want to resurrect Dmitrys Attributes RFC that was rejected for 7.1 in
> > 2016 with a few changes, incorporating feedback from the mailing list back
> > then and from talking to previous no voters.
> >
> > The RFC is at https://wiki.php.net/rfc/attributes_v2
> >
> > A working patch is at https://github.com/beberlei/php-src/pull/2 though
> > work around the details is still necessary.
> >
> > The RFC contains a section with common criticism and objections to
> > attributes, and I hope to have collected and responded to a good amount
> > already from previous discussions.
> >
> > There is also a fair amount of implementation detail still up for debate,
> > which is noted in "Open Issues". I have pre-committed to one approach, but
> > listed alternatives there. On these issues I am looking for your feedback.
> >
> > greetings
> > Benjamin
> >
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php