From 6540b9233ba052dbd3ef5113b2a70514da848a27 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 25 Aug 2025 15:56:15 +1000 Subject: [PATCH 1/3] add function.get_lineno function line number represents the first line of the definition of the currently executing function, which can differ from execute_data.opcode rename execute_data.get_lineno to get_opline_lineno to better describe what the value is --- phper/src/functions.rs | 11 +++++++++++ phper/src/values.rs | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/phper/src/functions.rs b/phper/src/functions.rs index 1180903..b492cad 100644 --- a/phper/src/functions.rs +++ b/phper/src/functions.rs @@ -670,6 +670,17 @@ impl ZFunc { } } + /// Gets the line number of the declaration of the currently + /// executing function. + pub fn get_lineno(&self) -> Option { + unsafe { + match u32::from(self.inner.type_) { + ZEND_USER_FUNCTION | ZEND_EVAL_CODE => Some(self.inner.op_array.line_start), + _ => 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 f58c067..cb39819 100644 --- a/phper/src/values.rs +++ b/phper/src/values.rs @@ -133,7 +133,7 @@ impl ExecuteData { /// 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 { + pub fn get_opline_lineno(&self) -> Option { unsafe { match u32::from((*self.inner.func).type_) { ZEND_USER_FUNCTION | ZEND_EVAL_CODE => { From 7282cc7dbc31829af1767166dbb517b9f93aedd2 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 25 Aug 2025 15:58:06 +1000 Subject: [PATCH 2/3] doc fix for class name typehint class_name was a bug, but I missed the doc update when fixing this previously --- phper-doc/doc/_06_module/_02_register_functions/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phper-doc/doc/_06_module/_02_register_functions/index.md b/phper-doc/doc/_06_module/_02_register_functions/index.md index 138a6ce..452ff9d 100644 --- a/phper-doc/doc/_06_module/_02_register_functions/index.md +++ b/phper-doc/doc/_06_module/_02_register_functions/index.md @@ -115,7 +115,7 @@ The output of `php --re` for this function would look like: Function [ function my_function ] { - Parameters [3] { - Parameter #0 [ ?class_name $a_class ] + Parameter #0 [ ?\MyNamespace\MyInterface $a_class ] Parameter #1 [ string $name = 'my_default' ] Parameter #2 [ bool $optional_bool = ] } From b6fce00f2132c6f61ba7e1d5d7f1de7645ba2a84 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 25 Aug 2025 16:06:52 +1000 Subject: [PATCH 3/3] line_start and line_end expose op_array.line_start and line_end, per https://github.com/php/php-src/blob/master/Zend/zend_compile.h#L548 --- phper/src/functions.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/phper/src/functions.rs b/phper/src/functions.rs index b492cad..d13e113 100644 --- a/phper/src/functions.rs +++ b/phper/src/functions.rs @@ -670,9 +670,9 @@ impl ZFunc { } } - /// Gets the line number of the declaration of the currently + /// Gets the start line number of the declaration of the currently /// executing function. - pub fn get_lineno(&self) -> Option { + pub fn get_line_start(&self) -> Option { unsafe { match u32::from(self.inner.type_) { ZEND_USER_FUNCTION | ZEND_EVAL_CODE => Some(self.inner.op_array.line_start), @@ -681,6 +681,17 @@ impl ZFunc { } } + /// Gets the end line number of the declaration of the currently + /// executing function. + pub fn get_line_end(&self) -> Option { + unsafe { + match u32::from(self.inner.type_) { + ZEND_USER_FUNCTION | ZEND_EVAL_CODE => Some(self.inner.op_array.line_end), + _ => None, + } + } + } + /// Get the function or method fully-qualified name. pub fn get_function_or_method_name(&self) -> ZString { unsafe {