Commit 2f08869
committed
Address review: tighter guards + lazy-object safety + engine-routed dynamic writes
Review feedback from @arnaudlb (PR #12):
1. Simplify dc_is_backed_declared_property():
!(pi->flags & ZEND_ACC_VIRTUAL) already implies pi->offset ==
ZEND_VIRTUAL_PROPERTY_OFFSET, and IS_HOOKED_PROPERTY_OFFSET() is only
meaningful on offsets returned by zend_get_property_offset(), not on
the raw pi->offset. Collapse to a single bitmask test.
2. Narrow the backed-enum scalar cast:
Add `(ZEND_TYPE_PURE_MASK(pi->type) & ~MAY_BE_NULL) == 0` so the cast
only fires for types of the form `Enum` or `?Enum`. Unions like
`Enum|string|int` already accept the scalar literally — casting it to
the enum case would be surprising.
3. Lazy-object safety in dc_write_backed_property():
Check !zend_lazy_object_initialized(obj) at the top and, when the flag
is absent, route through zend_update_property_ex() which triggers the
lazy realization hook. Direct OBJ_PROP slot writes on a lazy ghost
left it in a half-initialized state. DEEPCLONE_HYDRATE_NO_LAZY_INIT
keeps its existing opt-out fast path.
4. Dynamic-property fallback via zend_update_property_ex():
Swap zend_std_write_property() for zend_update_property_ex() so any
overridden write_property handler on internal classes or extensions
is respected. Picks up the appropriate scope via scope_ce ?: obj_ce.
A2 (null → unset on non-nullable typed) and A3 (scalar → backed-enum
cast) stay property-type-only, as discussed: the coercions are driven
by the target type at hydration time, which is stable within a single
execution.1 parent 5116a1f commit 2f08869
1 file changed
Lines changed: 27 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
638 | 638 | | |
639 | 639 | | |
640 | 640 | | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
650 | 647 | | |
651 | 648 | | |
652 | 649 | | |
| |||
736 | 733 | | |
737 | 734 | | |
738 | 735 | | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
739 | 745 | | |
740 | 746 | | |
741 | 747 | | |
| |||
773 | 779 | | |
774 | 780 | | |
775 | 781 | | |
776 | | - | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
777 | 787 | | |
778 | 788 | | |
779 | 789 | | |
| |||
3337 | 3347 | | |
3338 | 3348 | | |
3339 | 3349 | | |
3340 | | - | |
3341 | | - | |
3342 | | - | |
3343 | | - | |
| 3350 | + | |
| 3351 | + | |
| 3352 | + | |
| 3353 | + | |
| 3354 | + | |
| 3355 | + | |
| 3356 | + | |
3344 | 3357 | | |
3345 | 3358 | | |
3346 | 3359 | | |
| |||
0 commit comments