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

Conversation

brettmc
Copy link
Contributor

@brettmc brettmc commented Aug 21, 2025

This pull request adds new utility methods to the ZFunc and ExecuteData structs in the phper crate, providing improved access to function metadata and execution context information. These additions make it easier to retrieve function types, filenames, line numbers, and return values when working with PHP internals from Rust.

Function metadata access improvements:

  • Added get_type to ZFunc for retrieving the function type (e.g., ZEND_USER_FUNCTION, ZEND_INTERNAL_FUNCTION).
  • Added get_filename to ZFunc to obtain the filename for user-defined or eval'd functions using the op_array.

Execution context access improvements:

  • Added get_lineno to ExecuteData to retrieve the current source code line number for user or eval'd functions.
  • Added get_return_value, get_return_value_mut, get_return_value_mut_ptr, and get_return_value_ptr to ExecuteData for accessing the return value in various forms (immutable, mutable, and raw pointers).

When observing a function via observer API or zend_execute_*, these
additional functions allow looking up the function's type and the
filename (for user functions and eval'd code).
From ExecuteData we can also retrieve the return value in a number of
ways.
@brettmc brettmc requested a review from Copilot August 21, 2025 04:54
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enhances the phper crate by adding utility methods to access function metadata and execution context information when working with PHP internals from Rust.

  • Added function type and filename retrieval methods to ZFunc
  • Added line number and return value access methods to ExecuteData
  • Provided multiple variants for return value access (immutable, mutable, and raw pointers)

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
phper/src/functions.rs Adds get_type() and get_filename() methods to ZFunc for retrieving function metadata
phper/src/values.rs Adds get_lineno() and return value access methods to ExecuteData for execution context information

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

/// 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.

@jmjoy jmjoy merged commit 5021078 into phper-framework:master Aug 23, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants