On Thu, Mar 4, 2021, at 7:53 AM, Nikita Popov wrote:

> I've added a section that describes reflection methods. It works exactly as
> you say.
> 
> There is one interesting case though: How should
> ReflectionObject::newInstanceWithoutConstructor() work? In the current
> implementation, it will still evaluate the property defaults, including new
> expressions. This makes sense to me, but I can also see an argument that
> this method should not evaluate them -- however, in that case I believe it
> should not initialize any properties at all (leave them in "uninitialized"
> state). Populating property default values depending on what kind of
> expression they contain seems like a no-go to me.
> 
> @Ben Ramsey: Yes, it's possible to use nested new. Generally, all supported
> constant expressions can be freely combined.
> 
> Regards,
> Nikita

Would that then end up allowing enum cases to have an object backing value?

enum Suit {
  case Hearts = new Heart;
  case Spades = new Spade;
}

Or is there something else that would prevent that?  (I know Ilija ran into 
some complications there.)

Overall, I think the benefit to attributes alone justifies this RFC.  Endorse.

--Larry Garfield

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

Reply via email to