pub enum Value<X: Extension = Never> {
Null,
Bool(bool),
Int(i64),
Float(f64),
Str(Str),
Array(Array<X>),
Object(Array<X>),
Ext(X),
}Expand description
A PHP value.
Variants§
Null
PHP null.
Bool(bool)
A PHP bool.
Int(i64)
A PHP int.
Float(f64)
A PHP float.
Str(Str)
A PHP string, as bytes.
Array(Array<X>)
A PHP array.
Object(Array<X>)
A stdClass instance: its properties in order (string keys, not normalised).
Ext(X)
An object of another class.
Implementations§
Source§impl<X: Extension> Value<X>
impl<X: Extension> Value<X>
Sourcepub fn debug_type(&self) -> &str
pub fn debug_type(&self) -> &str
get_debug_type().
Sourcepub fn to_php_string(&self) -> Result<Str, EngineError>
pub fn to_php_string(&self) -> Result<Str, EngineError>
(string) $v (zval_get_string): floats at the precision setting, arrays
"Array" (PHP also warns); objects throw Error.
Sourcepub fn to_double(&self) -> f64
pub fn to_double(&self) -> f64
(float) $v (zval_get_double): strings by their leading number,
arrays 0.0 or 1.0, objects 1.0 (PHP warns).
Sourcepub fn strict_eq(&self, o: &Self) -> bool
pub fn strict_eq(&self, o: &Self) -> bool
$a === $b: same type and value; arrays with the same keys in the
same order and identical values. Objects are never identical (see the
module docs).
Sourcepub fn cmp_php(&self, o: &Self) -> Ordering
pub fn cmp_php(&self, o: &Self) -> Ordering
PHP 8 $a <=> $b. Uncomparable values (an array missing a key of the
other, objects of different classes, NaN) are Greater, as in PHP.
Sourcepub fn compare(&self, o: &Self) -> i32
pub fn compare(&self, o: &Self) -> i32
zend_compare: -1, 0 or 1 (1 also for uncomparable values).
Sourcepub fn from_json(v: &Json) -> Self
pub fn from_json(v: &Json) -> Self
The request-model value of JSON, as Utopia\Http\Request decodes a
body: objects are arrays (keys normalised), except empty ones, which
stay stdClass; integers beyond i64 are floats.
Sourcepub fn to_json(&self) -> Json
pub fn to_json(&self) -> Json
JSON for this value: lists are arrays, other arrays and objects are
objects (integer keys as strings). Lossy where JSON cannot hold the
value: invalid UTF-8 becomes U+FFFD and non-finite floats null.
Use crate::json::encode for PHP’s exact json_encode.
Source§impl<X: Extension> Value<X>
impl<X: Extension> Value<X>
Sourcepub fn try_to_json(&self) -> Option<Json>
pub fn try_to_json(&self) -> Option<Json>
The request-model JSON of this value, exactly: like Value::to_json
(lists are arrays, other arrays and objects are objects with integer
keys as strings, an extension object its to_array()), but None
where JSON cannot hold the value: a non-finite float, or a string or
key that is not UTF-8.
use php_std::{Str, Value};
use serde_json::json;
let list: Value = Value::from_json(&json!(["a", {"b": 1}]));
assert_eq!(list.try_to_json(), Some(json!(["a", {"b": 1}])));
assert_eq!(Value::<php_std::Never>::Str(Str::copy_from(&[0xff])).try_to_json(), None);
assert_eq!(Value::<php_std::Never>::Float(f64::INFINITY).try_to_json(), None);Trait Implementations§
Source§impl<X: Extension> FromIterator<Value<X>> for Array<X>
A list.
impl<X: Extension> FromIterator<Value<X>> for Array<X>
A list.
Source§fn from_iter<T: IntoIterator<Item = Value<X>>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = Value<X>>>(iter: T) -> Self
A list of the values.