Skip to content

provide access to return_value, function's type, filename, line number #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions phper/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
45 changes: 45 additions & 0 deletions phper/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
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 {
Expand Down
Loading