Skip to content

Commit 74924ad

Browse files
authored
Fix get_function_or_method_name when included file is scoped (#8467)
1 parent 722e9b9 commit 74924ad

6 files changed

+40
-2
lines changed

Zend/zend_execute_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ ZEND_API zend_string *get_active_function_or_method_name(void) /* {{{ */
504504

505505
ZEND_API zend_string *get_function_or_method_name(const zend_function *func) /* {{{ */
506506
{
507-
if (func->common.scope) {
507+
if (func->common.scope && func->common.function_name) {
508508
return zend_create_member_string(func->common.scope->name, func->common.function_name);
509509
}
510510

ext/zend_test/test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ static ZEND_FUNCTION(zend_weakmap_dump)
261261
RETURN_ARR(zend_array_dup(&ZT_G(global_weakmap)));
262262
}
263263

264+
static ZEND_FUNCTION(zend_get_current_func_name)
265+
{
266+
ZEND_PARSE_PARAMETERS_NONE();
267+
268+
zend_string *function_name = get_function_or_method_name(EG(current_execute_data)->prev_execute_data->func);
269+
270+
RETURN_STR(function_name);
271+
}
272+
264273
/* TESTS Z_PARAM_ITERABLE and Z_PARAM_ITERABLE_OR_NULL */
265274
static ZEND_FUNCTION(zend_iterable)
266275
{

ext/zend_test/test.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function zend_weakmap_attach(object $object, mixed $value): bool {}
6666
function zend_weakmap_remove(object $object): bool {}
6767
function zend_weakmap_dump(): array {}
6868

69+
function zend_get_current_func_name(): string {}
70+
6971
}
7072

7173
namespace ZendTestNS {

ext/zend_test/test_arginfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: a6755b9cb5c4625e91d69f17c3aa702a189ba01c */
2+
* Stub hash: 1f8834339ebf0d56d2e4ec7f3d27d837f61ba5ef */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -62,6 +62,9 @@ ZEND_END_ARG_INFO()
6262

6363
#define arginfo_zend_weakmap_dump arginfo_zend_test_array_return
6464

65+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_get_current_func_name, 0, 0, IS_STRING, 0)
66+
ZEND_END_ARG_INFO()
67+
6568
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ZendTestNS2_ZendSubNS_namespaced_func, 0, 0, _IS_BOOL, 0)
6669
ZEND_END_ARG_INFO()
6770

@@ -97,6 +100,7 @@ static ZEND_FUNCTION(zend_iterable);
97100
static ZEND_FUNCTION(zend_weakmap_attach);
98101
static ZEND_FUNCTION(zend_weakmap_remove);
99102
static ZEND_FUNCTION(zend_weakmap_dump);
103+
static ZEND_FUNCTION(zend_get_current_func_name);
100104
static ZEND_FUNCTION(namespaced_func);
101105
static ZEND_METHOD(_ZendTestClass, is_object);
102106
static ZEND_METHOD(_ZendTestClass, __toString);
@@ -123,6 +127,7 @@ static const zend_function_entry ext_functions[] = {
123127
ZEND_FE(zend_weakmap_attach, arginfo_zend_weakmap_attach)
124128
ZEND_FE(zend_weakmap_remove, arginfo_zend_weakmap_remove)
125129
ZEND_FE(zend_weakmap_dump, arginfo_zend_weakmap_dump)
130+
ZEND_FE(zend_get_current_func_name, arginfo_zend_get_current_func_name)
126131
ZEND_NS_FE("ZendTestNS2\\ZendSubNS", namespaced_func, arginfo_ZendTestNS2_ZendSubNS_namespaced_func)
127132
ZEND_FE_END
128133
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
return zend_get_current_func_name();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
get_function_or_method_name when included file is scoped
3+
--SKIPIF--
4+
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
5+
--FILE--
6+
<?php
7+
8+
class Foo
9+
{
10+
public static function bar()
11+
{
12+
return require 'get_function_or_method_name_01.inc';
13+
}
14+
}
15+
16+
var_dump(Foo::bar());
17+
?>
18+
--EXPECT--
19+
string(4) "main"

0 commit comments

Comments
 (0)