On 05/01/2016 10:47 PM, Larry Garfield wrote:
On 04/30/2016 06:21 PM, Rowan Collins wrote:
On 30/04/2016 23:45, Stanislav Malyshev wrote:
Oh, 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,

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.

The RFC proposes only Reflection*::getAttributres() that returns by value.
You may modify the returned copy, but the original attributes are immutable.

Thanks. Dmitry.

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 Garfield



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to