Expand description
The PHP value model: Value, Str, Array, ArrayKey.
One model for every crate that carries PHP values (request payloads,
documents, cache entries, queue messages), with the engine’s semantics:
byte strings, ordered arrays with integer and string keys, stdClass,
integers distinct from floats. The codecs (crate::json,
crate::serialize, crate::igbinary), type juggling and comparison
(Value::loose_eq, Value::cmp_php) and sorting (crate::sort)
work on it.
| PHP | Rust |
|---|---|
null, bool, int, float | Value::Null, Value::Bool, Value::Int, Value::Float |
string (bytes) | Value::Str / Str |
array | Value::Array / Array, keys ArrayKey |
stdClass | Value::Object (its property table, string keys as given) |
other objects (Utopia\Database\Document, …) | Value::Ext, an Extension |
ZEND_HANDLE_NUMERIC_STR | ArrayKey::normalize, numeric_key |
gettype, (bool), (string), (float) | Value::type_name, Value::truthy, Value::to_php_string, Value::to_double |
==, ===, <=> (zend_compare) | Value::loose_eq, Value::strict_eq, Value::cmp_php, Value::compare |
Utopia\Http\Request body decoding | Value::from_json |
Values have no identity: PHP references and shared instances are copies
here. Two object values are never === (separately created PHP objects
are distinct instances), which is the one place where identity shows.
Against the skeleton in rfc/rust-database.md: Array::iter yields
borrowed KeyRefs (a packed array stores no keys), and the engine’s
packed-array bookkeeping is part of Array because it decides the next
free index (see its docs).
Structs§
- Array
- A PHP array: an ordered map from
ArrayKeytoValue. - Array
Full $a[] = $vfailed: the next integer key would be pastPHP_INT_MAX(“Cannot add element to the array as the next element is already occupied”).- Engine
Error - An engine error thrown while juggling a value:
TypeError,ValueError,JsonException, orError(an object that cannot become a string). - Str
- A PHP string: bytes, not necessarily UTF-8.
Enums§
- Array
Key - A PHP array key: an integer or a byte string.
- Iter
- Entries of an
Arrayin order. - KeyRef
- A borrowed
ArrayKey, used to look keys up and to iterate packed arrays (which store no keys). - Never
- No extension: plain PHP values.
- Value
- A PHP value.
Traits§
- Extension
- Objects of classes other than
stdClassthat a crate carries inValue::Ext(for the database:DocumentandOperator).
Functions§
- numeric_
key ZEND_HANDLE_NUMERIC_STR: the integer a string array key becomes, if any.