Skip to content

Commit b4c6d5f

Browse files
committed
Properly render 2+ namespaces functions in build/gen_stub.php
Affects both INIT_NS_CLASS_ENTRY and ZEND_NS_FE Add test cases of the global function and namespaced values Closes GH-6664
1 parent 320843f commit b4c6d5f

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

build/gen_stub.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,10 @@ public function getFunctionEntry(): string {
818818
}
819819

820820
if ($namespace) {
821+
// Render A\B as "A\\B" in C strings for namespaces
821822
return sprintf(
822823
"\tZEND_NS_FE(\"%s\", %s, %s)\n",
823-
$namespace, $declarationName, $this->getArgInfoName());
824+
addslashes($namespace), $declarationName, $this->getArgInfoName());
824825
} else {
825826
return sprintf("\tZEND_FE(%s, %s)\n", $declarationName, $this->getArgInfoName());
826827
}
@@ -1222,7 +1223,7 @@ public function getRegistration(): string
12221223
$code .= "\tzend_class_entry ce, *class_entry;\n\n";
12231224
if (count($this->name->parts) > 1) {
12241225
$className = $this->name->getLast();
1225-
$namespace = $this->name->slice(0, -1);
1226+
$namespace = addslashes((string) $this->name->slice(0, -1));
12261227

12271228
$code .= "\tINIT_NS_CLASS_ENTRY(ce, \"$namespace\", \"$className\", class_{$escapedName}_methods);\n";
12281229
} else {

ext/zend_test/test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ static ZEND_FUNCTION(zend_iterable)
236236
ZEND_PARSE_PARAMETERS_END();
237237
}
238238

239+
static ZEND_FUNCTION(namespaced_func)
240+
{
241+
ZEND_PARSE_PARAMETERS_NONE();
242+
RETURN_TRUE;
243+
}
244+
239245
static zend_object *zend_test_class_new(zend_class_entry *class_type) /* {{{ */ {
240246
zend_object *obj = zend_objects_new(class_type);
241247
object_properties_init(obj, class_type);
@@ -323,6 +329,10 @@ static ZEND_METHOD(ZendTestNS2_Foo, method) {
323329
ZEND_PARSE_PARAMETERS_NONE();
324330
}
325331

332+
static ZEND_METHOD(ZendTestNS2_ZendSubNS_Foo, method) {
333+
ZEND_PARSE_PARAMETERS_NONE();
334+
}
335+
326336
PHP_INI_BEGIN()
327337
STD_PHP_INI_BOOLEAN("zend_test.observer.enabled", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_enabled, zend_zend_test_globals, zend_test_globals)
328338
STD_PHP_INI_BOOLEAN("zend_test.observer.show_output", "1", PHP_INI_SYSTEM, OnUpdateBool, observer_show_output, zend_zend_test_globals, zend_test_globals)

ext/zend_test/test.stub.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,13 @@ public function method(): void {}
9090
}
9191

9292
}
93+
94+
namespace ZendTestNS2\ZendSubNS {
95+
96+
class Foo {
97+
public function method(): void {}
98+
}
99+
100+
function namespaced_func(): bool {}
101+
102+
}

ext/zend_test/test_arginfo.h

Lines changed: 26 additions & 3 deletions
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: 950679cde15789a9060d4798dc35dc5a590fd8b2 */
2+
* Stub hash: 74e25e800964d6ecc2dfd783e7d738e3776c664c */
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()
@@ -51,6 +51,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_iterable, 0, 1, IS_VOID, 0)
5151
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arg2, IS_ITERABLE, 1, "null")
5252
ZEND_END_ARG_INFO()
5353

54+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ZendTestNS2_ZendSubNS_namespaced_func, 0, 0, _IS_BOOL, 0)
55+
ZEND_END_ARG_INFO()
56+
5457
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestClass_is_object, 0, 0, IS_LONG, 0)
5558
ZEND_END_ARG_INFO()
5659

@@ -60,13 +63,14 @@ ZEND_END_ARG_INFO()
6063
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestClass_returnsStatic, 0, 0, IS_STATIC, 0)
6164
ZEND_END_ARG_INFO()
6265

63-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestTrait_testMethod, 0, 0, _IS_BOOL, 0)
64-
ZEND_END_ARG_INFO()
66+
#define arginfo_class__ZendTestTrait_testMethod arginfo_ZendTestNS2_ZendSubNS_namespaced_func
6567

6668
#define arginfo_class_ZendTestNS_Foo_method arginfo_zend_test_void_return
6769

6870
#define arginfo_class_ZendTestNS2_Foo_method arginfo_zend_test_void_return
6971

72+
#define arginfo_class_ZendTestNS2_ZendSubNS_Foo_method arginfo_zend_test_void_return
73+
7074

7175
static ZEND_FUNCTION(zend_test_array_return);
7276
static ZEND_FUNCTION(zend_test_nullable_array_return);
@@ -81,12 +85,14 @@ static ZEND_FUNCTION(zend_string_or_object_or_null);
8185
static ZEND_FUNCTION(zend_string_or_stdclass);
8286
static ZEND_FUNCTION(zend_string_or_stdclass_or_null);
8387
static ZEND_FUNCTION(zend_iterable);
88+
static ZEND_FUNCTION(namespaced_func);
8489
static ZEND_METHOD(_ZendTestClass, is_object);
8590
static ZEND_METHOD(_ZendTestClass, __toString);
8691
static ZEND_METHOD(_ZendTestClass, returnsStatic);
8792
static ZEND_METHOD(_ZendTestTrait, testMethod);
8893
static ZEND_METHOD(ZendTestNS_Foo, method);
8994
static ZEND_METHOD(ZendTestNS2_Foo, method);
95+
static ZEND_METHOD(ZendTestNS2_ZendSubNS_Foo, method);
9096

9197

9298
static const zend_function_entry ext_functions[] = {
@@ -103,6 +109,7 @@ static const zend_function_entry ext_functions[] = {
103109
ZEND_FE(zend_string_or_stdclass, arginfo_zend_string_or_stdclass)
104110
ZEND_FE(zend_string_or_stdclass_or_null, arginfo_zend_string_or_stdclass_or_null)
105111
ZEND_FE(zend_iterable, arginfo_zend_iterable)
112+
ZEND_NS_FE("ZendTestNS2\\ZendSubNS", namespaced_func, arginfo_ZendTestNS2_ZendSubNS_namespaced_func)
106113
ZEND_FE_END
107114
};
108115

@@ -147,6 +154,12 @@ static const zend_function_entry class_ZendTestNS2_Foo_methods[] = {
147154
ZEND_FE_END
148155
};
149156

157+
158+
static const zend_function_entry class_ZendTestNS2_ZendSubNS_Foo_methods[] = {
159+
ZEND_ME(ZendTestNS2_ZendSubNS_Foo, method, arginfo_class_ZendTestNS2_ZendSubNS_Foo_method, ZEND_ACC_PUBLIC)
160+
ZEND_FE_END
161+
};
162+
150163
zend_class_entry *register_class__ZendTestInterface()
151164
{
152165
zend_class_entry ce, *class_entry;
@@ -252,3 +265,13 @@ zend_class_entry *register_class_ZendTestNS2_Foo()
252265
return class_entry;
253266
}
254267

268+
zend_class_entry *register_class_ZendTestNS2_ZendSubNS_Foo()
269+
{
270+
zend_class_entry ce, *class_entry;
271+
272+
INIT_NS_CLASS_ENTRY(ce, "ZendTestNS2\\ZendSubNS", "Foo", class_ZendTestNS2_ZendSubNS_Foo_methods);
273+
class_entry = zend_register_internal_class_ex(&ce, NULL);
274+
275+
return class_entry;
276+
}
277+

0 commit comments

Comments
 (0)