Type Definition ext_php_rs::zend::ExecutorGlobals
source · pub type ExecutorGlobals = _zend_executor_globals;
Expand description
Stores global variables used in the PHP executor.
Implementations§
source§impl ExecutorGlobals
impl ExecutorGlobals
sourcepub fn get() -> GlobalReadGuard<Self>
pub fn get() -> GlobalReadGuard<Self>
Returns a reference to the PHP executor globals.
The executor globals are guarded by a RwLock. There can be multiple immutable references at one time but only ever one mutable reference. Attempting to retrieve the globals while already holding the global guard will lead to a deadlock. Dropping the globals guard will release the lock.
sourcepub fn class_table(&self) -> Option<&ZendHashTable>
pub fn class_table(&self) -> Option<&ZendHashTable>
Attempts to retrieve the global class hash table.
sourcepub fn take_exception() -> Option<ZBox<ZendObject>>
pub fn take_exception() -> Option<ZBox<ZendObject>>
Attempts to extract the last PHP exception captured by the interpreter.
Returned inside a ZBox
.
This function requires the executor globals to be mutably held, which could lead to a deadlock if the globals are already borrowed immutably or mutably.
Examples found in repository?
src/types/callable.rs (line 128)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
pub fn try_call(&self, params: Vec<&dyn IntoZvalDyn>) -> Result<Zval> {
if !self.0.is_callable() {
return Err(Error::Callable);
}
let mut retval = Zval::new();
let len = params.len();
let params = params
.into_iter()
.map(|val| val.as_zval(false))
.collect::<Result<Vec<_>>>()?;
let packed = params.into_boxed_slice();
let result = unsafe {
_call_user_function_impl(
std::ptr::null_mut(),
self.0.as_ref() as *const crate::ffi::_zval_struct as *mut crate::ffi::_zval_struct,
&mut retval,
len as _,
packed.as_ptr() as *mut _,
std::ptr::null_mut(),
)
};
if result < 0 {
Err(Error::Callable)
} else if let Some(e) = ExecutorGlobals::take_exception() {
Err(Error::Exception(e))
} else {
Ok(retval)
}
}
More examples
src/types/object.rs (line 340)
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
fn from_zend_object(obj: &ZendObject) -> Result<Self> {
let mut ret = Zval::new();
unsafe {
zend_call_known_function(
(*obj.ce).__tostring,
obj as *const _ as *mut _,
obj.ce,
&mut ret,
0,
std::ptr::null_mut(),
std::ptr::null_mut(),
);
}
if let Some(err) = ExecutorGlobals::take_exception() {
// TODO: become an error
let class_name = obj.get_class_name();
panic!(
"Uncaught exception during call to {}::__toString(): {:?}",
class_name.expect("unable to determine class name"),
err
);
} else if let Some(output) = ret.extract() {
Ok(output)
} else {
// TODO: become an error
let class_name = obj.get_class_name();
panic!(
"{}::__toString() must return a string",
class_name.expect("unable to determine class name"),
);
}
}