Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108918 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 47396 invoked from network); 9 Mar 2020 20:58:10 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 9 Mar 2020 20:58:10 -0000 To: internals@lists.php.net References: Date: Mon, 9 Mar 2020 20:18:54 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 176.10.220.192 Subject: Re: [RFC] Attributes v2 From: ajf@ajf.me (Andrea Faulds) Message-ID: Benjamin Eberlei wrote: > 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 Hi, I have concerns about these two statements in the RFC: > The name of an attribute is resolved against the currently active namespace import scope during compilation. The resolved class names are then autoloaded to make sure they exist. > Consistent with PHP expressions in general, no validation is performed if the provided attribute arguments are fullfilling the contract of the attribute class constructor. This would happen only when accessing attributes as objects in the Reflection API (below). These two details are inconsistent with eachother: use of an annotation triggers an autoload, yet we aren't using the class that is autoloaded to validate it? This seems quite wasteful: if we have loaded the class, we might as well use it to check the arguments are correct. Also, why are we privileging the class existing over the arguments to the class being correct? If the arguments can be validated at Reflection time, surely the autoloading can be done then too? Both types of coding mistake are important. It also seems inconsistent with existing PHP behaviour, I think normally mentioning a class either triggers an immediate autoload and actual execution/validation (`new`) or it doesn't (a type declaration). This proposal is a strange half-way house. Is this being done to avoid paying the cost of creating the object at compilation time? Because I think triggering the autoload is going to be expensive anyway, possibly moreso. On a different note, the wording here is syntactically ambiguous. It can be read as both "if the provided attribute arguments are fullfilling the contract […], then no validation is performed" and "no validation is performed as to whether the provided attribute arguments are fullfilling the contract". I read it as the former the first time, which confused me for a moment. Another thing: > Thanks to class name resolving, IDEs or static analysis tools can perform this validation for the developer. Is this referencing the autoloading behaviour? I don't see why that would be required. (You could also be referring to the fact you use classes, which IDEs can look for, instead of arbitrary string attributes, which IDEs can not, which does make sense.) Thanks, Andrea