Skip to main content

Module semantics

Module semantics 

Source
Expand description

PHP value semantics the WordPress ports lean on: empty(), array reads and writes, array_merge(), integer keys, the (array) and (string) casts and PHP 8’s loose ==.

Functions§

array_merge
array_merge( $base, $over ): string keys of $over replace in place or append; int keys are renumbered from 0 across both arrays.
bytes_truthy
PHP truth of a byte string: "" and "0" are false, every other string is true.
get
$array['name'] for a string key.
is_empty
PHP’s empty(): null, false, 0, 0.0, "", "0" and array() are empty.
is_integer_key
Whether PHP turns this string array key into an int key ("10" becomes 10; "010", "-0" and "1e3" stay).
isset
isset( $array['name'] ): present and not null.
key_to_string
An array key as text: an int in decimal, a string as it is (lossily, when it is not UTF-8).
loose_eq
PHP 8’s $a == $b.
set
$array['name'] = $value: replaces in place, or appends.
to_array
(array) $value: an array as it is, an object’s properties (integer-like names as int keys), an enum as its name alone (no value, even for a backed enum: PhpValue::Enum carries no value), null as array(), and any other value as array( 0 => $value ).
to_array_key
$array[ $value ]’s key: null is "", a bool 0 or 1, a float truncated toward zero (a finite float outside the int range wraps modulo 2^64, as PHP 8.5’s zend_dval_to_lval() does: 1e20 is 7766279631452241920, 2^63 is i64::MIN; NaN and infinities are 0), an integer-like string an int; None for an array or object, where PHP throws “Illegal offset type”.
to_php_int
(int) $value (PHP 8.5, 64-bit): null and false 0, true 1; arrays 0 when empty, else 1; objects 1. A PhpValue::Ref is an unresolved back-reference and reads as null, 0; an object reference is 1.
to_php_string
(string) $value: null and false "", true "1", ints in decimal, floats as PHP 8 prints them (precision 14), arrays "Array". Objects have no __toString() here; they print their class name.
unset
unset( $array['name'] ): drops every entry with that string key.