Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 (ZEND_USER_FUNCTION,
/// ZEND_INTERNAL_FUNCTION, etc).
pub fn get_type(&self) -> u8 {
unsafe { self.inner.type_ }
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider returning a more type-safe enum instead of a raw u8. This would make the API more self-documenting and prevent invalid function type values.

Suggested change
unsafe { self.inner.type_ }
pub fn get_type(&self) -> Option<FunctionType> {
FunctionType::from_u8(unsafe { self.inner.type_ })

Copilot uses AI. Check for mistakes.

}

/// 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 filename_ptr = self.inner.op_array.filename;
if !filename_ptr.is_null() {
ZStr::try_from_ptr(filename_ptr)
} else {
None
}
}
_ => 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() {
Some((*opline).lineno)
} else {
None
}
}
_ => 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 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 associated return value pointer.
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