value
ModulePHP value semantics (type juggling) on top of serde_json::Value.
Request parameters reach PHP code as PHP values. These functions answer
the questions libraries ask about them (is_numeric, truthiness, string
casts, ==) the way the engine does.
Contents
use php_std::value::Number;pub enum NumberA PHP number after $value + 0.
use php_std::value::array_len;pub fn array_len(value: &Value) -> usizeNumber of elements of a PHP array value.
use php_std::value::array_values;pub fn array_values(value: &Value) -> Box<dyn Iterator<Item = &Value> + '_>Iterates the elements of a PHP array value (list or map) in order.
use php_std::value::compare_numbers;pub fn compare_numbers(x: Number, y: Number) -> OrderingPHP 8 <=> for two numbers.
use php_std::value::empty;pub fn empty(value: &Value) -> boolPHP empty($value).
use php_std::value::is_object;pub fn is_object(value: &Value) -> boolAn empty JSON object: a stdClass instance in PHP.
use php_std::value::json_number;pub fn json_number(n: &serde_json::Number) -> NumberA JSON number as PHP sees it: integers beyond i64 are floats.
use php_std::value::le_numbers;pub fn le_numbers(a: Number, b: Number) -> boolPHP 8 $a <= $b for two numbers (zend_is_smaller_or_equal): integers
compare exactly; otherwise both are floats, ZEND_THREEWAY_COMPARE is
not below zero for NAN, so any comparison with NAN is false.
use php_std::value::loose_eq;pub fn loose_eq(a: &Value, b: &Value) -> boolPHP 8 loose equality ($a == $b).
use php_std::value::loose_str_eq;pub fn loose_str_eq(a: &[u8], b: &[u8]) -> boolPHP $a == $b for two strings (zendi_smart_str_equals): two numeric
strings compare as numbers, anything else byte for byte. Numeric strings
are ASCII, so a string that is not UTF-8 only equals itself.
use php_std::value::numeric;pub fn numeric(value: &Value) -> Option<Number>PHP is_numeric($v) ? $v + 0 : null.
use php_std::value::numeric_bytes_ex;pub fn numeric_bytes_ex(s: &[u8]) -> Option<(Number, i8)>numeric_str_ex on bytes (a numeric string is ASCII, so bytes that
are not UTF-8 are never numeric).
use php_std::value::numeric_str;pub fn numeric_str(s: &str) -> Option<Number>PHP numeric-string parsing (is_numeric + + 0).
use php_std::value::numeric_str_ex;pub fn numeric_str_ex(s: &str) -> Option<(Number, i8)>Like numeric_str, also reporting integer overflow as the engine's
is_numeric_string_ex does: 1 or -1 when an integer-looking string
did not fit in i64 and became a float.
Leading and trailing whitespace (space, \t, \n, \r, \v, \f) is
allowed; the body is an optional sign and a decimal integer or float with
an optional exponent. Hex, octal and binary literals are not numeric.
use php_std::value::to_string;pub fn to_string(value: &Value) -> Option<String>PHP (string) $value for scalars; None for arrays and objects.
use php_std::value::truthy;pub fn truthy(value: &Value) -> boolPHP truthiness ((bool) $value).