diff --git a/phper/src/functions.rs b/phper/src/functions.rs index 4bf4cca..1180903 100644 --- a/phper/src/functions.rs +++ b/phper/src/functions.rs @@ -647,6 +647,29 @@ impl ZFunc { } } + /// Get the type of the function (sys::ZEND_USER_FUNCTION, + /// sys::ZEND_INTERNAL_FUNCTION, or sys::ZEND_EVAL_CODE). + pub fn get_type(&self) -> u32 { + unsafe { self.inner.type_ as u32 } + } + + /// For a user function or eval'd code, get the filename from op_array. + pub fn get_filename(&self) -> Option<&ZStr> { + unsafe { + match u32::from(self.inner.type_) { + ZEND_USER_FUNCTION | ZEND_EVAL_CODE => { + let ptr = self.inner.op_array.filename; + if ptr.is_null() { + None + } else { + ZStr::try_from_ptr(ptr) + } + } + _ => None, + } + } + } + /// Get the function or method fully-qualified name. pub fn get_function_or_method_name(&self) -> ZString { unsafe { diff --git a/phper/src/values.rs b/phper/src/values.rs index 8fa32df..f58c067 100644 --- a/phper/src/values.rs +++ b/phper/src/values.rs @@ -130,6 +130,51 @@ impl ExecuteData { unsafe { ZFunc::from_mut_ptr(self.inner.func) } } + /// Gets the current opline line number if available. This represents the + /// line number in the source code where the current operation is being + /// executed. + pub fn get_lineno(&self) -> Option { + unsafe { + match u32::from((*self.inner.func).type_) { + ZEND_USER_FUNCTION | ZEND_EVAL_CODE => { + let opline = self.inner.opline; + if opline.is_null() { + None + } else { + Some((*opline).lineno) + } + } + _ => None, + } + } + } + + /// Gets associated return value. + pub fn get_return_value(&self) -> Option<&ZVal> { + unsafe { + let val = self.inner.return_value; + ZVal::try_from_ptr(val) + } + } + + /// Gets mutable reference to associated return value. + pub fn get_return_value_mut(&mut self) -> Option<&mut ZVal> { + unsafe { + let val = self.inner.return_value; + ZVal::try_from_mut_ptr(val) + } + } + + /// Gets associated return value pointer. + pub fn get_return_value_mut_ptr(&mut self) -> *mut ZVal { + self.inner.return_value as *mut ZVal + } + + /// Gets immutable pointer to associated return value. + pub fn get_return_value_ptr(&self) -> *const ZVal { + self.inner.return_value as *const ZVal + } + /// Gets associated `$this` object if exists. pub fn get_this(&mut self) -> Option<&ZObj> { unsafe {