Re: Attributes/Annotations Case Study: Drupal
| From: | Larry Garfield | Date: | Sun, 01 May 2016 19:47:35 +0000 |
| Subject: | Re: Attributes/Annotations Case Study: Drupal | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93022@lists.php.net to get a copy of this message | ||
On 04/30/2016 06:21 PM, Rowan Collins wrote:
On 30/04/2016 23:45, Stanislav Malyshev wrote:It would never occur to me to not have it regenerated on each access. If I want to cache it I will do so myself, thanks. :-) However, that is not an issue created by using a defined structure for the annotation result. The RFC currently says it returns an associative array, aka anonymous struct. Those are always highly mutable. A classed object is as mutable as its design allows it to be. To wit: <<__Annotation>> class Definition { protected $foo; protected $bar; public function getFoo() {} public function getBar() {} } <<Definition(foo => 1, bar => 2)>> class Meep {} The resulting annotation object would be an instance of Definition, which is for practical purposes immutable. If it were returned as an array ['foo' => 1, 'bar' => 2], that would obviously be mutable. Whether Definition should have mutator methods on it then becomes the implementer's decision, which is probably for the best. --Larry GarfieldOh, of course you can have methods, but then it is strange conceptually - you have a normal class, which some other part of the language just uses for something else that classes are not routinely used for. I.e., does it call a constructor? When? With which arguments? What if it fails? What if I just create an object of this class - would it be the same as annotation object?Hm... I was going to say "well, PDO does this if you use PDOStatement::fetchObject"; but then I remembered that the integration with the object there IS a bit weird - it injects raw properties, and *then* calls the constructor. So, I'm not sure there's a limitation in terms of the object being data-only per se, but there are certainly oddities to be dealt with in terms of construction. And as you mentioned, mutability leads to another set of oddities - are the mutations stored for next time you request that annotation, or is the object recreated on each access? Regards,