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 6669181

Browse filesBrowse files
committed
Render anonymous classes correctly on php 8.
1 parent 6d7c696 commit 6669181
Copy full SHA for 6669181

File tree

10 files changed

+51
-18
lines changed
Filter options

10 files changed

+51
-18
lines changed

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"symfony/polyfill-intl-idn": "^1.10",
3232
"symfony/polyfill-mbstring": "~1.0",
3333
"symfony/polyfill-php72": "~1.5",
34-
"symfony/polyfill-php73": "^1.11"
34+
"symfony/polyfill-php73": "^1.11",
35+
"symfony/polyfill-php80": "^1.17"
3536
},
3637
"replace": {
3738
"symfony/asset": "self.version",

‎src/Symfony/Component/Console/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Application.php
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -863,17 +863,20 @@ private function doActuallyRenderThrowable(\Throwable $e, OutputInterface $outpu
863863
do {
864864
$message = trim($e->getMessage());
865865
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
866-
$class = \get_class($e);
867-
$class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class;
866+
$class = get_debug_type($e);
868867
$title = sprintf(' [%s%s] ', $class, 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : '');
869868
$len = Helper::strlen($title);
870869
} else {
871870
$len = 0;
872871
}
873872

874-
if (false !== strpos($message, "class@anonymous\0")) {
875-
$message = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
876-
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
873+
if (str_contains($message, "@anonymous\0")) {
874+
$message = preg_replace_callback('/([\\\\\w]+)@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
875+
if ('class' === $m[1]) {
876+
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
877+
}
878+
879+
return $m[1].'@anonymous';
877880
}, $message);
878881
}
879882

‎src/Symfony/Component/Console/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"php": ">=7.1.3",
2020
"symfony/polyfill-mbstring": "~1.0",
2121
"symfony/polyfill-php73": "^1.8",
22+
"symfony/polyfill-php80": "^1.17",
2223
"symfony/service-contracts": "^1.1|^2"
2324
},
2425
"require-dev": {

‎src/Symfony/Component/Debug/Exception/FatalThrowableError.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Exception/FatalThrowableError.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FatalThrowableError extends FatalErrorException
2626

2727
public function __construct(\Throwable $e)
2828
{
29-
$this->originalClassName = \get_class($e);
29+
$this->originalClassName = get_debug_type($e);
3030

3131
if ($e instanceof \ParseError) {
3232
$severity = E_PARSE;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Exception/FlattenException.php
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static function createFromThrowable(\Throwable $exception, int $statusCod
6767
$e->setStatusCode($statusCode);
6868
$e->setHeaders($headers);
6969
$e->setTraceFromThrowable($exception);
70-
$e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : \get_class($exception));
70+
$e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : get_debug_type($exception));
7171
$e->setFile($exception->getFile());
7272
$e->setLine($exception->getLine());
7373

@@ -134,7 +134,11 @@ public function getClass()
134134
*/
135135
public function setClass($class)
136136
{
137-
$this->class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class;
137+
if (preg_match('/^([\\\\\w]+)@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', $class, $matches)) {
138+
$this->class = ('class' === $matches[1] ? get_parent_class($matches[0]) : $matches[1]).'@anonymous';
139+
} else {
140+
$this->class = $class;
141+
}
138142

139143
return $this;
140144
}
@@ -179,9 +183,13 @@ public function getMessage()
179183
*/
180184
public function setMessage($message)
181185
{
182-
if (false !== strpos($message, "class@anonymous\0")) {
183-
$message = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
184-
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
186+
if (str_contains($message, "@anonymous\0")) {
187+
$message = preg_replace_callback('/([\\\\\w]+)@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
188+
if ('class' === $m[1]) {
189+
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
190+
}
191+
192+
return $m[1].'@anonymous';
185193
}, $message);
186194
}
187195

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ public function testAnonymousClass()
355355

356356
$this->assertSame('RuntimeException@anonymous', $flattened->getClass());
357357

358+
$flattened->setClass(\get_class(new class('Oops') extends NotFoundHttpException {
359+
}));
360+
361+
$this->assertSame('Symfony\Component\HttpKernel\Exception\NotFoundHttpException@anonymous', $flattened->getClass());
362+
358363
$flattened = FlattenException::create(new \Exception(sprintf('Class "%s" blah.', \get_class(new class() extends \RuntimeException {
359364
}))));
360365

‎src/Symfony/Component/Debug/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/composer.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
],
1818
"require": {
1919
"php": ">=7.1.3",
20-
"psr/log": "~1.0"
20+
"psr/log": "~1.0",
21+
"symfony/polyfill-php80": "~1.17"
2122
},
2223
"conflict": {
2324
"symfony/http-kernel": "<3.4"

‎src/Symfony/Component/ErrorHandler/Exception/FlattenException.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorHandler/Exception/FlattenException.php
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static function createFromThrowable(\Throwable $exception, int $statusCod
7171
$e->setStatusCode($statusCode);
7272
$e->setHeaders($headers);
7373
$e->setTraceFromThrowable($exception);
74-
$e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : \get_class($exception));
74+
$e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : get_debug_type($exception));
7575
$e->setFile($exception->getFile());
7676
$e->setLine($exception->getLine());
7777

@@ -138,7 +138,11 @@ public function getClass(): string
138138
*/
139139
public function setClass($class): self
140140
{
141-
$this->class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class;
141+
if (preg_match('/^([\\\\\w]+)@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', $class, $matches)) {
142+
$this->class = ('class' === $matches[1] ? get_parent_class($matches[0]) : $matches[1]).'@anonymous';
143+
} else {
144+
$this->class = $class;
145+
}
142146

143147
return $this;
144148
}
@@ -195,9 +199,13 @@ public function getMessage(): string
195199
*/
196200
public function setMessage($message): self
197201
{
198-
if (false !== strpos($message, "class@anonymous\0")) {
199-
$message = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
200-
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
202+
if (str_contains($message, "@anonymous\0")) {
203+
$message = preg_replace_callback('/([\\\\\w]+)@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
204+
if ('class' === $m[1]) {
205+
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
206+
}
207+
208+
return $m[1].'@anonymous';
201209
}, $message);
202210
}
203211

‎src/Symfony/Component/ErrorHandler/Tests/Exception/FlattenExceptionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorHandler/Tests/Exception/FlattenExceptionTest.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ public function testAnonymousClass()
373373

374374
$this->assertSame('RuntimeException@anonymous', $flattened->getClass());
375375

376+
$flattened->setClass(\get_class(new class('Oops') extends NotFoundHttpException {
377+
}));
378+
379+
$this->assertSame('Symfony\Component\HttpKernel\Exception\NotFoundHttpException@anonymous', $flattened->getClass());
380+
376381
$flattened = FlattenException::createFromThrowable(new \Exception(sprintf('Class "%s" blah.', \get_class(new class() extends \RuntimeException {
377382
}))));
378383

‎src/Symfony/Component/ErrorHandler/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorHandler/composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"php": ">=7.1.3",
2020
"psr/log": "~1.0",
2121
"symfony/debug": "^4.4.5",
22+
"symfony/polyfill-php80": "^1.17",
2223
"symfony/var-dumper": "^4.4|^5.0"
2324
},
2425
"require-dev": {

0 commit comments

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