Skip to content

Commit d4e40dc

Browse files
authored
Fix GH-12558 Escape \N in generated stubs (#12562)
1 parent 4b82ed4 commit d4e40dc

File tree

6 files changed

+44
-4
lines changed

6 files changed

+44
-4
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ PHP NEWS
1010
property via trait). (ilutov)
1111
. Fixed segfault caused by weak references to FFI objects. (sj-i)
1212
. Fixed max_execution_time: don't delete an unitialized timer. (Kévin Dunglas)
13+
. Fixed bug GH-12558 (Arginfo soft-breaks with namespaced class return type
14+
if the class name starts with N). (kocsismate)
1315

1416
- DOM:
1517
. Fix registerNodeClass with abstract class crashing. (nielsdos)

build/gen_stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,10 @@ public function toOptimizerTypeMask(): string {
527527
}
528528

529529
public function toEscapedName(): string {
530-
// Escape backslashes, and also encode \u and \U to avoid compilation errors in generated macros
530+
// Escape backslashes, and also encode \u, \U, and \N to avoid compilation errors in generated macros
531531
return str_replace(
532-
['\\', '\\u', '\\U'],
533-
['\\\\', '\\\\165', '\\\\125'],
532+
['\\', '\\u', '\\U', '\\N'],
533+
['\\\\', '\\\\165', '\\\\125', '\\\\116'],
534534
$this->name
535535
);
536536
}

ext/zend_test/test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static zend_class_entry *zend_test_child_class_with_method_with_parameter_attrib
5252
static zend_class_entry *zend_test_forbid_dynamic_call;
5353
static zend_class_entry *zend_test_ns_foo_class;
5454
static zend_class_entry *zend_test_ns_unlikely_compile_error_class;
55+
static zend_class_entry *zend_test_ns_not_unlikely_compile_error_class;
5556
static zend_class_entry *zend_test_ns2_foo_class;
5657
static zend_class_entry *zend_test_ns2_ns_foo_class;
5758
static zend_class_entry *zend_test_unit_enum;
@@ -636,6 +637,13 @@ static ZEND_METHOD(ZendTestNS_UnlikelyCompileError, method)
636637
RETURN_NULL();
637638
}
638639

640+
static ZEND_METHOD(ZendTestNS_NotUnlikelyCompileError, method)
641+
{
642+
ZEND_PARSE_PARAMETERS_NONE();
643+
644+
RETURN_NULL();
645+
}
646+
639647
static ZEND_METHOD(ZendTestNS2_Foo, method)
640648
{
641649
ZEND_PARSE_PARAMETERS_NONE();
@@ -818,6 +826,7 @@ PHP_MINIT_FUNCTION(zend_test)
818826

819827
zend_test_ns_foo_class = register_class_ZendTestNS_Foo();
820828
zend_test_ns_unlikely_compile_error_class = register_class_ZendTestNS_UnlikelyCompileError();
829+
zend_test_ns_not_unlikely_compile_error_class = register_class_ZendTestNS_NotUnlikelyCompileError();
821830
zend_test_ns2_foo_class = register_class_ZendTestNS2_Foo();
822831
zend_test_ns2_ns_foo_class = register_class_ZendTestNS2_ZendSubNS_Foo();
823832

ext/zend_test/test.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ class UnlikelyCompileError {
190190
public function method(): ?UnlikelyCompileError {}
191191
}
192192

193+
class NotUnlikelyCompileError {
194+
/* This method signature would create a compile error due to the string
195+
* "ZendTestNS\NotUnlikelyCompileError" in the generated macro call */
196+
public function method(): ?NotUnlikelyCompileError {}
197+
}
193198
}
194199

195200
namespace ZendTestNS2 {

ext/zend_test/test_arginfo.h

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/zend_test/tests/gen_stub_test_01.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ $foo->foo = new \ZendTestNS2\ZendSubNS\Foo();
1111
var_dump($foo);
1212
$foo = new \ZendTestNS\UnlikelyCompileError();
1313
var_dump($foo);
14+
$foo = new \ZendTestNS\NotUnlikelyCompileError();
15+
var_dump($foo);
1416
?>
1517
--EXPECTF--
1618
object(ZendTestNS2\Foo)#%d (%d) {
@@ -24,3 +26,5 @@ object(ZendTestNS2\Foo)#%d (%d) {
2426
}
2527
object(ZendTestNS\UnlikelyCompileError)#%d (%d) {
2628
}
29+
object(ZendTestNS\NotUnlikelyCompileError)#%d (%d) {
30+
}

0 commit comments

Comments
 (0)