Skip to content

Fix get_function_or_method_name when included file is scoped #8467

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
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
2 changes: 1 addition & 1 deletion Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ ZEND_API zend_string *get_active_function_or_method_name(void) /* {{{ */

ZEND_API zend_string *get_function_or_method_name(const zend_function *func) /* {{{ */
{
if (func->common.scope) {
if (func->common.scope && func->common.function_name) {
return zend_create_member_string(func->common.scope->name, func->common.function_name);
}

Expand Down
9 changes: 9 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ static ZEND_FUNCTION(zend_weakmap_dump)
RETURN_ARR(zend_array_dup(&ZT_G(global_weakmap)));
}

static ZEND_FUNCTION(zend_get_current_func_name)
{
ZEND_PARSE_PARAMETERS_NONE();

zend_string *function_name = get_function_or_method_name(EG(current_execute_data)->prev_execute_data->func);

RETURN_STR(function_name);
}

/* TESTS Z_PARAM_ITERABLE and Z_PARAM_ITERABLE_OR_NULL */
static ZEND_FUNCTION(zend_iterable)
{
Expand Down
2 changes: 2 additions & 0 deletions ext/zend_test/test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function zend_weakmap_attach(object $object, mixed $value): bool {}
function zend_weakmap_remove(object $object): bool {}
function zend_weakmap_dump(): array {}

function zend_get_current_func_name(): string {}

}

namespace ZendTestNS {
Expand Down
7 changes: 6 additions & 1 deletion ext/zend_test/test_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: a6755b9cb5c4625e91d69f17c3aa702a189ba01c */
* Stub hash: 1f8834339ebf0d56d2e4ec7f3d27d837f61ba5ef */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -62,6 +62,9 @@ ZEND_END_ARG_INFO()

#define arginfo_zend_weakmap_dump arginfo_zend_test_array_return

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_get_current_func_name, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ZendTestNS2_ZendSubNS_namespaced_func, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

Expand Down Expand Up @@ -97,6 +100,7 @@ static ZEND_FUNCTION(zend_iterable);
static ZEND_FUNCTION(zend_weakmap_attach);
static ZEND_FUNCTION(zend_weakmap_remove);
static ZEND_FUNCTION(zend_weakmap_dump);
static ZEND_FUNCTION(zend_get_current_func_name);
static ZEND_FUNCTION(namespaced_func);
static ZEND_METHOD(_ZendTestClass, is_object);
static ZEND_METHOD(_ZendTestClass, __toString);
Expand All @@ -123,6 +127,7 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(zend_weakmap_attach, arginfo_zend_weakmap_attach)
ZEND_FE(zend_weakmap_remove, arginfo_zend_weakmap_remove)
ZEND_FE(zend_weakmap_dump, arginfo_zend_weakmap_dump)
ZEND_FE(zend_get_current_func_name, arginfo_zend_get_current_func_name)
ZEND_NS_FE("ZendTestNS2\\ZendSubNS", namespaced_func, arginfo_ZendTestNS2_ZendSubNS_namespaced_func)
ZEND_FE_END
};
Expand Down
3 changes: 3 additions & 0 deletions ext/zend_test/tests/get_function_or_method_name_01.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

return zend_get_current_func_name();
19 changes: 19 additions & 0 deletions ext/zend_test/tests/get_function_or_method_name_01.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
get_function_or_method_name when included file is scoped
--SKIPIF--
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
--FILE--
<?php

class Foo
{
public static function bar()
{
return require 'get_function_or_method_name_01.inc';
}
}

var_dump(Foo::bar());
?>
--EXPECT--
string(4) "main"