Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d2a4841

Browse filesBrowse files
bug #46170 Fix dumping enums on PHP 8.2 (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- Fix dumping enums on PHP 8.2 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Follows php/php-src#8233 Makes the CI green again on PHP 8.2. Replaces #46160 Commits ------- 4244aa8 Fix dumping enums on PHP 8.2
2 parents ff578de + 4244aa8 commit d2a4841
Copy full SHA for d2a4841

File tree

5 files changed

+12
-7
lines changed
Filter options

5 files changed

+12
-7
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ abstract protected function describeCallable($callable, array $options = []);
150150
*/
151151
protected function formatValue($value): string
152152
{
153+
if ($value instanceof \UnitEnum) {
154+
return ltrim(var_export($value, true), '\\');
155+
}
156+
153157
if (\is_object($value)) {
154158
return sprintf('object(%s)', \get_class($value));
155159
}
@@ -158,7 +162,7 @@ protected function formatValue($value): string
158162
return $value;
159163
}
160164

161-
return preg_replace("/\n\s*/s", '', var_export($value, true));
165+
return preg_replace("/\n\s*/s", '', ltrim(var_export($value, true)), '\\');
162166
}
163167

164168
/**
@@ -169,15 +173,15 @@ protected function formatValue($value): string
169173
protected function formatParameter($value): string
170174
{
171175
if ($value instanceof \UnitEnum) {
172-
return var_export($value, true);
176+
return ltrim(var_export($value, true), '\\');
173177
}
174178

175179
// Recursively search for enum values, so we can replace it
176180
// before json_encode (which will not display anything for \UnitEnum otherwise)
177181
if (\is_array($value)) {
178182
array_walk_recursive($value, static function (&$value) {
179183
if ($value instanceof \UnitEnum) {
180-
$value = var_export($value, true);
184+
$value = ltrim(var_export($value, true), '\\');
181185
}
182186
});
183187
}

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private function writeData(array $data, array $options)
162162
// before json_encode (which will not display anything for \UnitEnum otherwise)
163163
array_walk_recursive($data, static function (&$value) {
164164
if ($value instanceof \UnitEnum) {
165-
$value = var_export($value, true);
165+
$value = ltrim(var_export($value, true), '\\');
166166
}
167167
});
168168

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
343343
} elseif ($argument instanceof Definition) {
344344
$argumentsInformation[] = 'Inlined Service';
345345
} elseif ($argument instanceof \UnitEnum) {
346-
$argumentsInformation[] = var_export($argument, true);
346+
$argumentsInformation[] = ltrim(var_export($argument, true), '\\');
347347
} else {
348348
$argumentsInformation[] = \is_array($argument) ? sprintf('Array (%d element(s))', \count($argument)) : $argument;
349349
}

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom): array
388388
}
389389
} elseif ($argument instanceof \UnitEnum) {
390390
$argumentXML->setAttribute('type', 'constant');
391-
$argumentXML->appendChild(new \DOMText(var_export($argument, true)));
391+
$argumentXML->appendChild(new \DOMText(ltrim(var_export($argument, true), '\\')));
392392
} else {
393393
$argumentXML->appendChild(new \DOMText($argument));
394394
}

‎src/Symfony/Component/VarExporter/Internal/Exporter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/Internal/Exporter.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,13 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
195195
public static function export($value, $indent = '')
196196
{
197197
switch (true) {
198-
case \is_int($value) || \is_float($value) || $value instanceof \UnitEnum: return var_export($value, true);
198+
case \is_int($value) || \is_float($value): return var_export($value, true);
199199
case [] === $value: return '[]';
200200
case false === $value: return 'false';
201201
case true === $value: return 'true';
202202
case null === $value: return 'null';
203203
case '' === $value: return "''";
204+
case $value instanceof \UnitEnum: return ltrim(var_export($value, true), '\\');
204205
}
205206

206207
if ($value instanceof Reference) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.