Skip to content

Commit 5e06dad

Browse files
committed
Properly render 2+ namespaces functions in build/gen_stub.php
Affects ZEND_NS_FE Add test cases of the global function Backported to php 8.0 from GH-6664
1 parent f23bfc4 commit 5e06dad

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

build/gen_stub.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,10 @@ public function getFunctionEntry(): string {
793793
}
794794

795795
if ($namespace) {
796+
// Render A\B as "A\\B" in C strings for namespaces
796797
return sprintf(
797798
"\tZEND_NS_FE(\"%s\", %s, %s)\n",
798-
$namespace, $declarationName, $this->getArgInfoName());
799+
addslashes($namespace), $declarationName, $this->getArgInfoName());
799800
} else {
800801
return sprintf("\tZEND_FE(%s, %s)\n", $declarationName, $this->getArgInfoName());
801802
}

ext/zend_test/test.c

Lines changed: 6 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);

ext/zend_test/test.stub.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,9 @@ public function method(): void {}
6363
}
6464

6565
}
66+
67+
namespace ZendTestNS2\ZendSubNS {
68+
69+
function namespaced_func(): bool {}
70+
71+
}

ext/zend_test/test_arginfo.h

Lines changed: 7 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: 759463b1adece643974a9c51455789aef11ba935 */
2+
* Stub hash: d98281072c6eeb5631dbf3ba975807f49a553b3e */
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,8 +63,7 @@ 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

@@ -81,6 +83,7 @@ static ZEND_FUNCTION(zend_string_or_object_or_null);
8183
static ZEND_FUNCTION(zend_string_or_stdclass);
8284
static ZEND_FUNCTION(zend_string_or_stdclass_or_null);
8385
static ZEND_FUNCTION(zend_iterable);
86+
static ZEND_FUNCTION(namespaced_func);
8487
static ZEND_METHOD(_ZendTestClass, is_object);
8588
static ZEND_METHOD(_ZendTestClass, __toString);
8689
static ZEND_METHOD(_ZendTestClass, returnsStatic);
@@ -103,6 +106,7 @@ static const zend_function_entry ext_functions[] = {
103106
ZEND_FE(zend_string_or_stdclass, arginfo_zend_string_or_stdclass)
104107
ZEND_FE(zend_string_or_stdclass_or_null, arginfo_zend_string_or_stdclass_or_null)
105108
ZEND_FE(zend_iterable, arginfo_zend_iterable)
109+
ZEND_NS_FE("ZendTestNS2\\ZendSubNS", namespaced_func, arginfo_ZendTestNS2_ZendSubNS_namespaced_func)
106110
ZEND_FE_END
107111
};
108112

0 commit comments

Comments
 (0)