Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109708 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95935 invoked from network); 19 Apr 2020 23:48:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Apr 2020 23:48:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CE8511801FD for ; Sun, 19 Apr 2020 15:19:44 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 19 Apr 2020 15:19:43 -0700 (PDT) Received: by mail-wr1-f53.google.com with SMTP id i10so9801774wrv.10 for ; Sun, 19 Apr 2020 15:19:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beberlei-de.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fBnK0RU6d3GqY8hfs7tMqOgltNVJ3k27jq4fjjqiloo=; b=fs9fNjL+VbkmwXxB8syvEvs7/70nCIS6vRGpI+YgvmB89+lLIYlmN8XDMIwxFptSkz T3Zb5IclUHOBQmjfRJQeXvDCaT1yfy3Ea/21t35oj+X20S9JlejR3JvCnguA6414kx4q EKF6h01KAJYWLniB8jnZlPirxhCSaGZm49JgNc6Y+B6YClGfOWbFPtDGdn9AKTsTGBgC cXo8QKbVhFlsyC/Yy1RTNyJhDZKkdsIVD6ZTaU2y+29yUifu9l/OHKp1NojsvmyZDQOs Pom1+XSQ+tsK13V9HSlfgx7W6R6hunTTnN3IhAwwTqAGSv+JS6eqLMZRNiCqanBKQ1i1 lElw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fBnK0RU6d3GqY8hfs7tMqOgltNVJ3k27jq4fjjqiloo=; b=IbLSLxp1F6fvG1EGYXCKTf2i+Iukcjng3H0Jj15RKoralUxEJi82QmslTO0+5+CnHF vK6XRYtWjPruJuA3G4TuXI2IS96rnsV8YoX9SkfP5ErlLLfvjDr1NnhoBUovITLI8TRh KpP7MAXgmhLuL5jFyAEbaLLotcB3+MBo6nRrtkIhUg25yyU+M1GOkqBbv8ZASbib5ZD7 RrIPHj7NwIbzknuzEa64TOak3asCO09zcfZWrEFWEISG5QahUZC4SCZhoEpt/jWl8uBG Zj1E5WIyZrYeZFbCFOC9uiMbn3PkweJM2OoIdXzKI0qN3G3ttR8aRF/i3fsKVxbPP+FG /ofw== X-Gm-Message-State: AGi0PuYO4CU37eT7TWtziF9FS22WTWfVJj2JFmOStR+np6XTi6GR7GbO JJtunww0d5Efyo/GStOtRSB5PPXFTiNxsHzJNcXVj2q8AIg= X-Google-Smtp-Source: APiQypKWhD/rmSNI6oI9yTRm50VflOcth4UaEGluZkLQnDPlbyGBGCmU5p0aULUuI02VAx5QASl1Xhou13lEbq/ZL9g= X-Received: by 2002:adf:b1c9:: with SMTP id r9mr3564185wra.271.1587334782366; Sun, 19 Apr 2020 15:19:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 20 Apr 2020 00:19:30 +0200 Message-ID: To: Niklas Keller Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000d7cbf205a3ac2d9c" Subject: Re: [PHP-DEV] Re: [RFC] Attributes v2 From: kontakt@beberlei.de (Benjamin Eberlei) --000000000000d7cbf205a3ac2d9c Content-Type: text/plain; charset="UTF-8" On Sun, Apr 19, 2020 at 11:30 PM Niklas Keller wrote: > 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 > > namespace My\Attributes; > > use PhpAttribute; > > <> > class SingleArgument > { > public $value; > > public function __construct(string $value) > { > $this->value = $value; > } > } > ``` > > I think this should be <> 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? > <> would best require a namespace (PHP\Attributes) as I feel claminig "Attribute" class in the main namespace might cause problems for users. But there is no PHP namespace yet and proposals about this have just gotten to the list. I have therefore looked to PhpToken from nikitas recent RFC as an example for naming, because several contributors mentioned that the PHP\Attributes namespace I suggested in an earlier version of the RFC would be an instant "no" vote, because of the lack of previous decision on this topic. The reason these are plain PHP objects and not some special case is that you can re-use them for configuration from different sources. Symfony Validator is a good example where the "attributes" could map to the validator configuration classes that are also used from XML, YAML, ... Yes, INSTANCE_OF attempts to load each attributes class, but if an attribute class cannot be looked up (not autoloadable) it gets skipped without error (subject to error handling of autoloader implementation, but for Composer it skips). > > 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: > The write-once / readonly RFC was rejected and only internal classes can implement this behavior (see ext/dom). But userland attributes also map to userland classes, so as you say this is not possible. However given this RFC maps to existing concepts. I don't see how preventing instantiation or requiring readonly in userland produces any benefits over this described use-case in the RFC. This would make attributes much stricter than everything else in the language, I don't see how its fair to impose this on a new feature like Attributes, when the language doesn't even have concepts for this strictness for regular classes (containing more important code). Mapping to "normal" classes is the way C# implements attributes, I don't think this should be more complex than that. Extensions, and Third Party library authors can easily guard their attribute classes against writes from the outside with the usual OOP abstractions and if application authors deem their attributes to be writable that is their business. > > ```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. > Named parameters might some day come to PHP in the future, and this is precisely the argument for treating an attribute like a regular php class with a constructor, because the named params syntax would look exactly the same in attribute declarations then, increasing language consistency. The reason I went with the C# way of mapping to a "plain class" is simplicity. The concept of attributes is already not the easiest nut to crack, inventing another keyword and a structure that looks like a class, but has very different implications requires a lot of words in the documentation and doesn't provide the easiest access to beginners. > > 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. > The name getAsObject is an implementation detail in my perspective. I am open for a better name. > > 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. > Sorry to hear and I hope you reconsider after reading my reply, as I built this RFC around extensibility in the future primarily to address a lot of voter feedback from the last RFCs. For example things you mentioned: named parameters, readonly properties, constructor property promotion, PHP namespace. These topics are all currently or recently discussed and would all automatically lead to improvements for attributes, when they "just" map to classes and their constructor. If we would go with special cases for Attributes, we have to solve all of these problems a second time, and this RFC would explode in complexity. > > Best, > Niklas > > > Am Fr., 17. Apr. 2020 um 12:49 Uhr schrieb Benjamin Eberlei > : > > > > 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 > 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 > > > > --000000000000d7cbf205a3ac2d9c--