Ilija Tovilo and I would like to offer another RFC for your consideration.
> It's been a while in coming, and we've evolved the design quite a bit just
> in the last week so if you saw an earlier draft of it in the past few
> months, I would encourage you to read it over again to make sure we're all
> on the same page. I'm actually pretty happy with where it ended up, even
> if it's not the original design. This approach eliminates several
> hard-to-implement edge cases while still providing a lot of functionality
> in one package.
>
> https://wiki.php.net/rfc/property-hooks
>
Congrats for the RFC for property hooks, I like it all, including
abbreviated forms, $value as default name, etc.
Some notes:
- does set($value) { mean set(mixed $value) { or set(TypeFromProp
$value) { ? I understand it would be the latter but it might be nice to
clarify (unless I missed it)
- function setFullName => ucfirst is not found in the "set" version
- could parent::$x::set($x) be replaced by parent::$x = $x ? Same for
the get variant? Why not if not?
- readonly: could this be supported by materializing them, using the
storage for memoization after first access? that'd be quite powerful
- I'm not sure we need ReflectionProperty::getHook('set') when we can
do getHooks()['set'] ?? null
- What does ReflectionMethod::getName return on a hook? And getClosure?
- Should we add ReflectionProperty::IS_VIRTUAL ?
- I'm a bit surprised by the possibility of adding attributes to hooks.
I'm not sure I see the use case and I think this might be confusing in
addition to attributes on the property itself.
- For serialization: exclude them from var_export() and serialize(),
which don't need virtual props to rebuild the state (you mean
json_encode(), not JsonSerializable on that list), call get for
var_dump/print_r when it's defined (but ignore exceptions). But (array) /
get_mangled_object_vars() / get_object_vars() shouldn't call any "get".
I have a bigger concern: the take on references contradicts with the intro
about BC breaks: turning a materialized property into virtual one would
break BC as far as refs are concerned. One idea to fix that: add a ref
hook, that must return a reference. If not implemented => Error when trying
to get-by-ref. This could also help solve the $foo->array[] case (including
the asym-visiblity issue).
Nicolas