You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
deprecations: silently deprecate get() and set(), teach property access everywhere
- get() and set() move to the Silent Aliases region of DeprecatedAliases:
same behavior, IDE strikethrough, no runtime signal. get('') and
set('', $value) stay the only way to reach an empty-string key, so the
''-key suggestions still name them.
- Docs and deprecation notices now point at property access only: ->key,
->key = $value, ->{'users.id'} for keys property syntax can't type, and
?? for missing-key defaults. Write-side [] notices suggest assignment
instead of ->set().
- README, help.txt, and UPGRADING drop get()/set(); the indexBy example
uses brace syntax.
- Tests: get()/set() behavior stays pinned in ReadAccessTest and
WriteAccessTest, the alias inventory and no-signal checks cover them in
DeprecationsTest, and incidental get()/set()/nth() calls in other tests
switch to property access and at().
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@
11
11
-`json_encode($smartArray)` also substitutes malformed UTF-8 in keys with � (U+FFFD), not just values - one corrupt byte in a key no longer makes it return false and lose the whole document.
12
12
13
13
### Added
14
-
-`at($index)` - new name for `nth()`: get an element by position, zero-based, negative indices count from the end. Matches JavaScript's `Array.at()`. `get()` is by key, `at()` is by position.
14
+
-`at($index)` - new name for `nth()`: get an element by position, zero-based, negative indices count from the end. Matches JavaScript's `Array.at()`. `$row->key` is by key, `at()` is by position.
15
15
-`columnAt($index)` - new name for `pluckNth()`: get the column at a position from each row, ignoring key names. `column()` is by key, `columnAt()` is by position.
16
16
17
17
### Changed
@@ -29,7 +29,7 @@
29
29
-`SmartArray::new($data, true)` and `SmartArrayHtml::new($data, false)` now throw like the constructors do, instead of silently ignoring the boolean. Old code that passed `true` expecting auto-encoding was silently getting raw, unencoded values - now it fails at the call site with the class to use instead. Redundant booleans (`false` on SmartArray, `true` on SmartArrayHtml) log a deprecation and proceed.
30
30
-`sortBy()` second parameter renamed `$type` → `$flags` - it always held PHP sort flags, and now matches `sort()` and PHP's own sort functions. Affects named-argument calls only: `sortBy('name', flags: SORT_NATURAL)`.
31
31
-`column(null)` and `column(null, null)` now match PHP's `array_column()`: whole rows renumbered from 0, instead of throwing "unexpected arguments"
32
-
- Array-syntax deprecation notices suggest one replacement style for reads, `isset()`, and `unset()`: `->key` for property-safe names, `->{0}` for integer keys, `->{'users.id'}` for other keys (`->get()` also works for reads). Reads used to suggest `->get(0)` while existence checks suggested `->{0}`, so one `empty()` call printed two notices with different advice. Null and `''` keys suggest `->get('')` - the brace form is a fatal error for an empty property name.
32
+
- Array-syntax deprecation notices suggest one replacement style across reads, writes, `isset()`, and `unset()`: `->key`and `->key = $value`for property-safe names, `->{0}` for integer keys, `->{'users.id'}` for other keys. Reads used to suggest `->get(0)` while existence checks suggested `->{0}`, so one `empty()` call printed two notices with different advice, and writes suggested the now-deprecated `->set()`. Null and `''` keys are the exception and suggest `->get('')` / `->set('', $value)` - the brace form is a fatal error for an empty property name.
33
33
-`isset($array['key'])` and `empty($array['key'])` now follow `$onOffsetAccess` like reads, writes, and `unset()` - notice by default, exception in `'throw'` mode. Existence checks were the one silent form of the deprecated `[]` syntax; if `[]` support is removed in a future version, `isset()` on the object would silently return false instead of erroring, so these call sites need migrating with the rest. Property-syntax checks (`isset($array->key)`) are unaffected and stay signal-free. Internal existence checks now call `array_key_exists()` directly, removing two method calls from every `get()`.
34
34
-`or404()` outputs `<html>` instead of `<html lang>` - an empty `lang` reads as an invalid value to accessibility checkers, and the message language is caller-supplied so it can't be declared. Matches SmartString.
35
35
-`orDie()` and `or404()` now exit with status 1 instead of 0, so shell scripts and cron jobs see the failure. Output is unchanged. Matches SmartString.
@@ -43,6 +43,8 @@
43
43
-`pluck($valueField, $keyField)` - use `column()` instead, same arguments and behavior: `->column('name')`, `->column('name', 'id')`. One name per behavior, and `column()` matches PHP's `array_column()`. Still works with no runtime notice - IDEs show a strikethrough with the replacement; removed from README and help().
44
44
-`each($callback)` - use a `foreach` loop instead, same behavior in plain PHP. Still works with no runtime notice - IDEs show a strikethrough with the replacement; removed from help(). It had no measured uses and a foreach is clearer and faster.
45
45
-`sprintf($format)` - use `map()` with an inline format string instead: `$list->map(fn($v) => "<li>$v</li>")`. On SmartArrayHtml, encode explicitly and convert to raw mode first so the finished HTML isn't re-encoded on output: `$row->asRaw()->map(fn($v) => "<td>" . htmlspecialchars((string)$v) . "</td>")->implode("\n")`. The method still works unchanged with no runtime notice - IDEs show a strikethrough with the replacement; removed from README and help(). It was a second formatting syntax that only saw use inside CMS Builder.
46
+
-`get($key, $default)` - use property access instead: `$row->name`, `$row->{'users.id'}` for keys property syntax can't type, and `$row->name ?? 'n/a'` for missing-key defaults. Still works unchanged with no runtime notice, including the default parameter - IDEs show a strikethrough with the replacement; removed from README and help(). It was a second documented way to read every element; the docs now teach one form, and property access is 1.1-1.6x faster. `get('')` remains the only way to read an empty-string key - the brace form is a fatal error.
47
+
-`set($key, $value)` - use property assignment instead: `$row->name = $value`, or `$row->{'users.id'} = $value` for keys property syntax can't type. Still works unchanged with no runtime notice - IDEs show a strikethrough with the replacement; removed from README and help(). Deprecated together with `get()` - one form for reads, one for writes. `set('', $value)` remains the only way to write an empty-string key.
46
48
47
49
### Removed
48
50
-`usingSmartStrings()` - use `instanceof SmartArrayHtml` to check the mode; the class is the mode. The method was never documented and had no found uses.
0 commit comments