Skip to content

Commit 624f2e3

Browse files
bug #34996 Fix displaying anonymous classes on PHP 7.4 (nicolas-grekas)
This PR was merged into the 4.3 branch. Discussion ---------- Fix displaying anonymous classes on PHP 7.4 | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Follows php/php-src@0f2cdbf#diff-3a8139128d4026ce0cb0c86beba4e6b9R6351 Commits ------- c36568a Fix displaying anonymous classes on PHP 7.4
2 parents b729b5c + c36568a commit 624f2e3

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ protected function doRenderException(\Exception $e, OutputInterface $output)
795795
}
796796

797797
if (false !== strpos($message, "class@anonymous\0")) {
798-
$message = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) {
798+
$message = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:)[0-9a-fA-F]++/', function ($m) {
799799
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
800800
}, $message);
801801
}

src/Symfony/Component/Debug/Exception/FlattenException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function getMessage()
172172
public function setMessage($message)
173173
{
174174
if (false !== strpos($message, "class@anonymous\0")) {
175-
$message = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) {
175+
$message = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:)[0-9a-fA-F]++/', function ($m) {
176176
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
177177
}, $message);
178178
}

src/Symfony/Component/Debug/ExceptionHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ public function getContent(FlattenException $exception)
252252
foreach ($e['trace'] as $trace) {
253253
$content .= '<tr><td>';
254254
if ($trace['function']) {
255-
$content .= sprintf('at <span class="trace-class">%s</span><span class="trace-type">%s</span><span class="trace-method">%s</span>(<span class="trace-arguments">%s</span>)', $this->formatClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
255+
$content .= sprintf('at <span class="trace-class">%s</span><span class="trace-type">%s</span><span class="trace-method">%s</span>', $this->formatClass($trace['class']), $trace['type'], $trace['function']);
256+
257+
if (isset($trace['args'])) {
258+
$content .= sprintf('(<span class="trace-arguments">%s</span>)', $this->formatArgs($trace['args']));
259+
}
256260
}
257261
if (isset($trace['file']) && isset($trace['line'])) {
258262
$content .= $this->formatPath($trace['file'], $trace['line']);

src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ public function flattenDataProvider()
237237

238238
public function testArguments()
239239
{
240+
if (\PHP_VERSION_ID >= 70400) {
241+
$this->markTestSkipped('PHP 7.4 removes arguments from exception traces.');
242+
}
243+
240244
$dh = opendir(__DIR__);
241245
$fh = tmpfile();
242246

@@ -299,6 +303,10 @@ function () {},
299303

300304
public function testRecursionInArguments()
301305
{
306+
if (\PHP_VERSION_ID >= 70400) {
307+
$this->markTestSkipped('PHP 7.4 removes arguments from exception traces.');
308+
}
309+
302310
$a = null;
303311
$a = ['foo', [2, &$a]];
304312
$exception = $this->createException($a);
@@ -310,6 +318,10 @@ public function testRecursionInArguments()
310318

311319
public function testTooBigArray()
312320
{
321+
if (\PHP_VERSION_ID >= 70400) {
322+
$this->markTestSkipped('PHP 7.4 removes arguments from exception traces.');
323+
}
324+
313325
$a = [];
314326
for ($i = 0; $i < 20; ++$i) {
315327
for ($j = 0; $j < 50; ++$j) {

src/Symfony/Component/VarDumper/Caster/ClassStub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(string $identifier, $callable = null)
5656
}
5757

5858
if (false !== strpos($identifier, "class@anonymous\0")) {
59-
$this->value = $identifier = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) {
59+
$this->value = $identifier = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:)[0-9a-fA-F]++/', function ($m) {
6060
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
6161
}, $identifier);
6262
}

src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private static function filterExceptionArray($xClass, array $a, $xPrefix, $filte
282282
unset($a[$xPrefix.'string'], $a[Caster::PREFIX_DYNAMIC.'xdebug_message'], $a[Caster::PREFIX_DYNAMIC.'__destructorException']);
283283

284284
if (isset($a[Caster::PREFIX_PROTECTED.'message']) && false !== strpos($a[Caster::PREFIX_PROTECTED.'message'], "class@anonymous\0")) {
285-
$a[Caster::PREFIX_PROTECTED.'message'] = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) {
285+
$a[Caster::PREFIX_PROTECTED.'message'] = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:)[0-9a-fA-F]++/', function ($m) {
286286
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
287287
}, $a[Caster::PREFIX_PROTECTED.'message']);
288288
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy