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
Copy file name to clipboardExpand all lines: docs/en/COMPILE_TIME_FUNCTIONS.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
@@ -63,18 +63,20 @@ There are currently 17 `std::` compile-time entry points.
63
63
|`std::list($valueType)`| Creates an integer-key typed PHP array with negative/sparse indices and append. | First assignment of a new function-local variable; strict dynamic keys, no dynamic reference mutation. |
64
64
|`std::dict($keyType, $valueType)`| Creates a typed PHP dictionary with `Type::Int` or `Type::Str` keys. | First assignment of a new function-local variable; explicit keys required, no append. |
65
65
66
-
Lists and dicts retain PHP array storage and copy-on-write without `toStd*()` recovery. Values require matching static types, while dynamic `any` / `var` keys receive internal strict checks. Only read-only dynamic PHP array calls are allowed, without `std::ref()`. Parameters need exactly matching `StdList` / `StdDict` type annotations, with the PHP type omitted or declared as `array`, never `mixed`; matching native `&` parameters can modify the caller's array. See [Typed PHP Arrays and Type Annotations](TYPED_ARRAYS.md) for examples and boundary details.
66
+
Lists and dicts retain PHP array storage and copy-on-write. Values require matching static types, while dynamic `any` / `var` keys receive internal strict checks. Only read-only dynamic PHP array calls are allowed, without `std::ref()`. Parameters need exactly matching `StdList` / `StdDict` type annotations, with the PHP type omitted or declared as `array`, never `mixed`; matching native `&` parameters can modify the caller's array. See [Typed PHP Arrays and Type Annotations](TYPED_ARRAYS.md) for examples and boundary details.
67
67
68
68
## Std container conversion keyword methods
69
69
70
-
There are currently 4 Std container conversion keyword methods.
70
+
There are currently 6 Std container conversion keyword methods.
71
71
72
72
| Name | Purpose | Main limitation |
73
73
| --- | --- | --- |
74
74
|`toStdArray(...)`| Wraps the variable as a std array. | Can only be used in the top-level scope of the variable's first assignment. |
75
75
|`toStdVector(...)`| Wraps the variable as a std vector. | Can only be used in the top-level scope of the variable's first assignment. |
76
76
|`toStdMap(...)`| Wraps the variable as a std map. | Can only be used in the top-level scope of the variable's first assignment. |
77
77
|`toStdOrderedMap(...)`| Wraps the variable as a std ordered map. | Can only be used in the top-level scope of the variable's first assignment. |
78
+
|`toStdList($valueType)`| Converts to an integer-key typed PHP array. | An identical contract copies directly; other sources receive strict key and value checks. |
79
+
|`toStdDict($keyType, $valueType)`| Converts to a typed PHP dictionary. | Keys must be `Type::Int` or `Type::Str`; other rules match `toStdList()`. |
Copy file name to clipboardExpand all lines: docs/en/TYPED_ARRAYS.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,12 @@ PHP types may be omitted or declared as compatible storage types: `array` for
24
24
`StdList` / `StdDict`, and `box` for `StdVector` / `StdMap` / `StdOrderedMap`.
25
25
Explicit `mixed`, `any`, nullable types, unions, and incompatible types are rejected.
26
26
27
+
`$source->toStdList(Type::Int)` and `$source->toStdDict(Type::Str, Type::Int)` convert values into new local typed arrays. A typed array with the same contract uses ordinary PHP array assignment. An ordinary array has every key and value checked strictly at runtime; other values first pass through `toArray()` and then receive the same checks. `ClassName::class` is accepted as a value type and checks that every value is an instance of that class. Conversion leaves the source array unchanged.
28
+
29
+
**Performance:** Except for direct assignment from a typed array with the same contract, conversion traverses the entire array and checks every key and value, taking O(n) time. Non-array sources also run `toArray()` first. Repeated conversion of large arrays, especially inside loops, can be costly. Use these methods carefully; convert once at the typed boundary and reuse the result when possible.
30
+
31
+
Validation uses the array's actual runtime key types. PHP normalizes numeric string keys such as `'123'` to integer keys, so an ordinary array with such a key fails the strict `toStdDict(Type::Str, ...)` check. A `StdDict` with the same contract is assigned directly and is not checked again.
32
+
27
33
List keys are integers, including negative and sparse keys; no bounds checks
28
34
are inserted. Only lists allow `[]` append. Dicts require an explicit int or
29
35
string key. Dynamic `any` / `var` keys get internal strict type checks, not coercion.
Copy file name to clipboardExpand all lines: docs/en/TYPE_ANNOTATIONS.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,7 @@ Parameter entry validates the Box, container kind, leaf type, and full shape bef
93
93
94
94
## StdList / StdDict keys and values
95
95
96
-
Typed PHP arrays primarily establish their constraints statically. They introduce no runtime typed-array object and require no PHPX or HashTable changes.
96
+
Typed PHP arrays primarily establish their constraints statically. They introduce no runtime typed-array object and do not change PHP HashTable storage. Explicit `toStdList()` / `toStdDict()` conversion uses PHPX `toTypedArray()` to check each entry of the source array.
97
97
98
98
- A list is an integer-key PHP array, allowing negative keys, sparse keys, and holes. It permits append.
99
99
- A dict declares Int or Str keys and requires explicit keys, even for integer-key dicts.
0 commit comments