Skip to content

Commit 87ac43d

Browse files
Add is_identical for zvals (#217)
1 parent 7ed31eb commit 87ac43d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

allowed_bindings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ bind! {
8888
zend_hash_str_update,
8989
zend_internal_arg_info,
9090
zend_is_callable,
91+
zend_is_identical,
9192
zend_long,
9293
zend_lookup_class_ex,
9394
zend_module_entry,

docsrs_bindings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,9 @@ extern "C" {
834834
cache_slot: *mut *mut ::std::os::raw::c_void,
835835
) -> ::std::os::raw::c_int;
836836
}
837+
extern "C" {
838+
pub fn zend_is_identical(op1: *mut zval, op2: *mut zval) -> bool;
839+
}
837840
extern "C" {
838841
pub fn zend_is_true(op: *mut zval) -> ::std::os::raw::c_int;
839842
}

src/types/zval.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::{
1111
convert::{FromZval, FromZvalMut, IntoZval, IntoZvalDyn},
1212
error::{Error, Result},
1313
ffi::{
14-
_zval_struct__bindgen_ty_1, _zval_struct__bindgen_ty_2, zend_is_callable, zend_resource,
15-
zend_value, zval, zval_ptr_dtor,
14+
_zval_struct__bindgen_ty_1, _zval_struct__bindgen_ty_2, zend_is_callable,
15+
zend_is_identical, zend_resource, zend_value, zval, zval_ptr_dtor,
1616
},
1717
flags::DataType,
1818
flags::ZvalTypeFlags,
@@ -327,6 +327,18 @@ impl Zval {
327327
unsafe { zend_is_callable(ptr as *mut Self, 0, std::ptr::null_mut()) }
328328
}
329329

330+
/// Checks if the zval is identical to another one.
331+
/// This works like `===` in php.
332+
///
333+
/// # Parameters
334+
///
335+
/// * `other` - The the zval to check identity against.
336+
pub fn is_identical(&self, other: &Self) -> bool {
337+
let self_p: *const Self = self;
338+
let other_p: *const Self = other;
339+
unsafe { zend_is_identical(self_p as *mut Self, other_p as *mut Self) }
340+
}
341+
330342
/// Returns true if the zval contains a pointer, false otherwise.
331343
pub fn is_ptr(&self) -> bool {
332344
self.get_type() == DataType::Ptr

0 commit comments

Comments
 (0)