Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109711 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63684 invoked from network); 20 Apr 2020 08:16:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Apr 2020 08:16:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C90CD1804F2 for ; Sun, 19 Apr 2020 23:48:00 -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=-2.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS6724 81.169.144.0/22 X-Spam-Virus: No X-Envelope-From: Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.219]) (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 23:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1587365277; s=strato-dkim-0002; d=kelunik.com; h=Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=E1XsWpTCPHmvn0p0IMc3XP1y5IkoEdP5UFtYfxoJZIo=; b=ryMEn7LbppQpbj0hYc/QqgKEZTX5TALX/iai0D1/Ph+Y2uGZawmgPKuqdfRvOAnvQ8 L3a3LqZr6gkGxh9cpE1BLfkcuWgXfwsUfK+rfloOFJ3q2NO/GRfmwILJVT1PWmJ5/jfO rcJyTL+9BBQyoxahvQSsEXfVcu+mwW4opONXz7lj3BeNVRscUu4oZQTEg5nlmIiGmksk pOTQ8PKiSmWGb/uFn3YLwY5wHE8b90HkC1Kgdj+CqZNl758YxeN91lqr0slasu5DEw3+ KUaLmBBcqg2Fb3H45JIHY3vxBfZWHWhMwY/L0W5KkCbcBRZijwusxJHdvVOzIyBemB9Z 0FpQ== X-RZG-AUTH: ":IWkkfkWkbvHsXQGmRYmUo9mlsGbEv0XHBzMIJSS+jKTzde5mDb8AaBEcYyFB" X-RZG-CLASS-ID: mo00 Received: from mail-vs1-f46.google.com by smtp.strato.de (RZmta 46.5.0 AUTH) with ESMTPSA id 605d46w3K6lvB1q (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Mon, 20 Apr 2020 08:47:57 +0200 (CEST) Received: by mail-vs1-f46.google.com with SMTP id h30so4850848vsr.5 for ; Sun, 19 Apr 2020 23:47:57 -0700 (PDT) X-Gm-Message-State: AGi0PuZdMz6J7o/jFDBp8Qt2BjAQEv4j/JSt4haTqCT2K7dfd8uPXgLF pZnG7KzqIejyE9eBj3qCgkpvd3xFC/RQrcgZ6ls= X-Google-Smtp-Source: APiQypJTN77WbmBs+qNM24QCu2rE1EQgHtWhYp4x3cyV1h/W0TZUuiZIC7CujcjRtNTXuKoxUHDbRCo8+FAtYjS8PIU= X-Received: by 2002:a67:1145:: with SMTP id 66mr1284591vsr.77.1587365276582; Sun, 19 Apr 2020 23:47:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 20 Apr 2020 08:47:45 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Benjamin Eberlei Cc: PHP Internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Re: [RFC] Attributes v2 From: me@kelunik.com (Niklas Keller) Hey Benjamin, thanks for your answers! > <> would best require a namespace (PHP\Attributes) as I feel > claminig "Attribute" class in the main namespace might cause problems for > users. While this is true, I don't see how Attribute is different to any classes introduced in the "recent" versions like \Generator or \Error. Maybe Nikita can run his analyzer to see how widespread its usage is? > 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. Some prefix is pretty similar to a namespace, and I don't like a new naming convention being part of this RFC. For PhpToken the naming might make sense, as "Token" alone might be seen as a too generic term. > 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, ... Sounds fine! > 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). This seems rather strange to me, but I can definitely see the value if you're using no-dev deployments, for example. I think I'd be better to disallow inheritance for attributes and skip the autoloading and INSTANCE_OF parameter here. > > > > 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'd be possible if the actual objects are created in core and userland only provides the contracts (interfaces) for these attributes. > 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. Readonly is just something I'd like to see, it's not a requirement and I'll still vote yes if the more important points are solved. What's more important here IMO is the restriction of inheritance, mainly because the raw arguments are exposed via reflection and won't be compatible between parent and child attribute in any case. There are a few options I see to solve this: - Require constructor compatibility for attribute classes (only other classes) - Forbid extending attribute classes entirely - Remove getArguments() from reflection I think my preferred solution would be to forbid inheritance, because that also solves the autoloading inconsistencies (given that implemented interfaces aren't respected in `ReflectionFunction::getAttributes()` and others. > 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. That's probably fine, yes, if `getAsObject()` / `toObject()` / `createObject()` always returns a new object. > 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. I guess writing your own annotations and processing them isn't a beginners topic, but using them to attribute code definitely is. > > > > 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. Do you know whether we already have something similar in core? > > 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. I think it's fine solving these in the future. However, the naming and autoloading behavior can't be solved in the future, so I hope we can get some improvements in before the vote. Best, Niklas