Skip to content

Commit 3d74226

Browse files
authored
Add get_id() and hash() methods on ZendObject (#196)
1 parent 9a105ab commit 3d74226

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/types/object.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,29 @@ impl ZendObject {
196196
T::from_zend_object(self)
197197
}
198198

199+
/// Returns an unique identifier for the object.
200+
///
201+
/// The id is guaranteed to be unique for the lifetime of the object.
202+
/// Once the object is destroyed, it may be reused for other objects.
203+
/// This is equivalent to calling the [`spl_object_id`] PHP function.
204+
///
205+
/// [`spl_object_id`]: https://www.php.net/manual/function.spl-object-id
206+
#[inline]
207+
pub fn get_id(&self) -> u32 {
208+
self.handle
209+
}
210+
211+
/// Computes an unique hash for the object.
212+
///
213+
/// The hash is guaranteed to be unique for the lifetime of the object.
214+
/// Once the object is destroyed, it may be reused for other objects.
215+
/// This is equivalent to calling the [`spl_object_hash`] PHP function.
216+
///
217+
/// [`spl_object_hash`]: https://www.php.net/manual/function.spl-object-hash.php
218+
pub fn hash(&self) -> String {
219+
format!("{:016x}0000000000000000", self.handle)
220+
}
221+
199222
/// Attempts to retrieve a reference to the object handlers.
200223
#[inline]
201224
unsafe fn handlers(&self) -> Result<&ZendObjectHandlers> {

0 commit comments

Comments
 (0)