Commit b838c3e
committed
Drop scoped mode — mangled-only is now the only shape (v0.5.0)
The scoped shape `[$className => ['prop' => $val]]` and the flat mangled
shape `['prop' => $val, "\0Class\0priv" => $val2]` were functionally
equivalent: both resolved each key to the same `property_info` entry and
performed the same direct slot write. Keeping both required an
intermediate `scoped_props` HashTable built by the `MANGLED_VARS` path,
a double-pass write loop, and a footgun guard to catch users passing
mangled keys without the flag.
Drop scoped mode entirely. `$vars` is always the flat `(array)`-cast
shape, which is also what Doctrine-style ORM hydrators get from PDO.
The parser now writes directly during the key-parse pass — no
`scoped_props` accumulation, no second-pass loop.
### BC breaks
- Scoped-shape input `[$class => ['prop' => $val]]` is no longer
understood. Callers migrate by flattening: bare names for public /
protected / most-derived-private, `"\0Scope\0prop"` for
parent-declared private.
- `DEEPCLONE_HYDRATE_MANGLED_VARS` constant removed (the mode is now
implicit). Drop the flag from `$flags` arguments.
- `DEEPCLONE_HYDRATE_PRESERVE_REFS` moves from `1 << 3` to `1 << 2`,
filling the slot vacated by `MANGLED_VARS`. Symbolic references via
the constant name are unaffected.
- A mangled-form key (`"\0*\0prop"` or `"\0Class\0prop"`) that doesn't
resolve to a declared slot on the resolved scope now raises
`ValueError("key scope X does not declare a Y property")` instead of
silently creating a dynamic property. A mangled-form key whose class
name isn't `obj_ce` or a parent still raises the existing
`"key scope X is not a parent of Y"` error.
### Code impact
- `deepclone.c`: -480 / +330 lines in `deepclone_hydrate()`. The
scoped-mode second-pass write loop (~200 lines), the
`MANGLED_VARS→scoped_props` intermediate builder (~140 lines), and
the footgun guard are gone.
- `deepclone.stub.php` + regenerated `deepclone_arginfo.h`:
`DEEPCLONE_HYDRATE_MANGLED_VARS` constant entry removed.
- `README.md`: rewritten the `$vars` section around the `(array)`-cast
shape, with a table of key shapes and their targets. The "scoped
mode" examples and the "which shape is faster" paragraph are gone.
- `CHANGELOG.md`: 0.5.0 entry documenting the BC break.
- `php_deepclone.h`: `PHP_DEEPCLONE_VERSION` `0.4.0` → `0.5.0`.
### Tests
All 30 phpt tests converted and passing locally on PHP 8.4 NTS. New
coverage:
- Bare name reaches a parent-private slot when the name is unambiguous.
- Mangled-form key with undeclared prop raises "does not declare"
(`"\0*\0undeclared"` and `"\0Parent\0undeclared"` cases).1 parent 55aa4ec commit b838c3e
16 files changed
Lines changed: 395 additions & 540 deletions
File tree
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
8 | 35 | | |
9 | 36 | | |
10 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
| 60 | + | |
60 | 61 | | |
61 | | - | |
62 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
77 | 73 | | |
78 | 74 | | |
79 | | - | |
| 75 | + | |
80 | 76 | | |
81 | 77 | | |
82 | 78 | | |
| |||
97 | 93 | | |
98 | 94 | | |
99 | 95 | | |
100 | | - | |
101 | | - | |
| 96 | + | |
| 97 | + | |
102 | 98 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
109 | 105 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 106 | + | |
| 107 | + | |
115 | 108 | | |
116 | 109 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
128 | 116 | | |
129 | 117 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
134 | 122 | | |
135 | 123 | | |
136 | 124 | | |
| |||
139 | 127 | | |
140 | 128 | | |
141 | 129 | | |
142 | | - | |
143 | 130 | | |
144 | 131 | | |
145 | 132 | | |
146 | | - | |
| 133 | + | |
147 | 134 | | |
148 | 135 | | |
149 | 136 | | |
| |||
185 | 172 | | |
186 | 173 | | |
187 | 174 | | |
188 | | - | |
189 | | - | |
| 175 | + | |
190 | 176 | | |
191 | 177 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
206 | 187 | | |
207 | 188 | | |
208 | 189 | | |
| |||
0 commit comments