[php-src] master: Add regression tests for `ReflectionEnum::__toString()` with null bytes
Daniel Scherzer <[email protected]>
| Newsgroups | gmane.comp.php.cvs.general |
|---|---|
| Message-ID | <[email protected]> |
Author: Daniel Scherzer (DanielEScherzer)
Date: 2026-07-14T06:36:32-07:00
Commit: https://github.com/php/php-src/commit/0fca39de812864a4262c1734143cafdd0efdd399
Raw diff: https://github.com/php/php-src/commit/0fca39de812864a4262c1734143cafdd0efdd399.diff
Add regression tests for `ReflectionEnum::__toString()` with null bytes
So that when the output is fixed the changes can be confirmed in tests
Changed paths:
A ext/reflection/tests/gh22681/ReflectionEnum_backed_value.phpt
Diff:
diff --git a/ext/reflection/tests/gh22681/ReflectionEnum_backed_value.phpt b/ext/reflection/tests/gh22681/ReflectionEnum_backed_value.phpt
new file mode 100644
index 000000000000..8131a3adafed
--- /dev/null
+++ b/ext/reflection/tests/gh22681/ReflectionEnum_backed_value.phpt
@@ -0,0 +1,61 @@
+--TEST--
+GH-22681: null bytes in backed value truncate ReflectionEnum::__toString()
+--FILE--
+<?php
+
+enum Demo: string {
+ case DEMO = "F\0oo";
+}
+
+$r = new ReflectionEnum(Demo::class);
+echo $r;
+var_dump( new ReflectionEnumBackedCase(Demo::class, 'DEMO')->getBackingValue() );
+?>
+--EXPECTF--
+Enum [ <user> enum Demo: string implements UnitEnum, BackedEnum ] {
+ @@ %s %d-%d
+
+ - Enum cases [1] {
+ Case DEMO = F
+ }
+
+ - Constants [0] {
+ }
+
+ - Static properties [0] {
+ }
+
+ - Static methods [3] {
+ Method [ <internal, prototype UnitEnum> static public method cases ] {
+
+ - Parameters [0] {
+ }
+ - Return [ array ]
+ }
+
+ Method [ <internal, prototype BackedEnum> static public method from ] {
+
+ - Parameters [1] {
+ Parameter #0 [ <required> string|int $value ]
+ }
+ - Return [ static ]
+ }
+
+ Method [ <internal, prototype BackedEnum> static public method tryFrom ] {
+
+ - Parameters [1] {
+ Parameter #0 [ <required> string|int $value ]
+ }
+ - Return [ ?static ]
+ }
+ }
+
+ - Properties [2] {
+ Property [ public protected(set) readonly string $name ]
+ Property [ public protected(set) readonly string $value ]
+ }
+
+ - Methods [0] {
+ }
+}
+string(4) "F%0oo"