Skip to content

Commit 64d145c

Browse files
bug #48615 Fix getting the name of closures on PHP 8.1.11+ (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- Fix getting the name of closures on PHP 8.1.11+ | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Leverages php/php-src#9299 Commits ------- bccd23d Fix getting the name of closures on PHP 8.1.11+
2 parents c47bedf + bccd23d commit 64d145c

File tree

12 files changed

+12
-11
lines changed

12 files changed

+12
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ private function getCallableData($callable): array
361361
}
362362
$data['name'] = $r->name;
363363

364-
if ($class = $r->getClosureScopeClass()) {
364+
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
365365
$data['class'] = $class->name;
366366
if (!$r->getClosureThis()) {
367367
$data['static'] = true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ protected function describeCallable($callable, array $options = [])
377377
}
378378
$string .= "\n".sprintf('- Name: `%s`', $r->name);
379379

380-
if ($class = $r->getClosureScopeClass()) {
380+
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
381381
$string .= "\n".sprintf('- Class: `%s`', $class->name);
382382
if (!$r->getClosureThis()) {
383383
$string .= "\n- Static: yes";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ private function formatCallable($callable): string
614614
if (str_contains($r->name, '{closure}')) {
615615
return 'Closure()';
616616
}
617-
if ($class = $r->getClosureScopeClass()) {
617+
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
618618
return sprintf('%s::%s()', $class->name, $r->name);
619619
}
620620

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ private function getCallableDocument($callable): \DOMDocument
548548
}
549549
$callableXML->setAttribute('name', $r->name);
550550

551-
if ($class = $r->getClosureScopeClass()) {
551+
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
552552
$callableXML->setAttribute('class', $class->name);
553553
if (!$r->getClosureThis()) {
554554
$callableXML->setAttribute('static', 'true');

src/Symfony/Bundle/SecurityBundle/Command/DebugFirewallCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private function formatCallable($callable): string
255255
if (false !== strpos($r->name, '{closure}')) {
256256
return 'Closure()';
257257
}
258-
if ($class = $r->getClosureScopeClass()) {
258+
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
259259
return sprintf('%s::%s()', $class->name, $r->name);
260260
}
261261

src/Symfony/Component/ErrorHandler/Internal/TentativeTypes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ class TentativeTypes
753753
'isVariadic' => 'bool',
754754
'isStatic' => 'bool',
755755
'getClosureThis' => '?object',
756+
'getClosureCalledClass' => '?ReflectionClass',
756757
'getClosureScopeClass' => '?ReflectionClass',
757758
'getDocComment' => 'string|false',
758759
'getEndLine' => 'int|false',

src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct($listener, ?string $name, Stopwatch $stopwatch, Even
4949
$r = new \ReflectionFunction($listener);
5050
if (str_contains($r->name, '{closure}')) {
5151
$this->pretty = $this->name = 'closure';
52-
} elseif ($class = $r->getClosureScopeClass()) {
52+
} elseif ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
5353
$this->name = $class->name;
5454
$this->pretty = $this->name.'::'.$r->name;
5555
} else {

src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function createArgumentMetadata($controller): array
3333
$class = $reflection->class;
3434
} else {
3535
$reflection = new \ReflectionFunction($controller);
36-
if ($class = str_contains($reflection->name, '{closure}') ? null : $reflection->getClosureScopeClass()) {
36+
if ($class = str_contains($reflection->name, '{closure}') ? null : (\PHP_VERSION_ID >= 80111 ? $reflection->getClosureCalledClass() : $reflection->getClosureScopeClass())) {
3737
$class = $class->name;
3838
}
3939
}

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ private function parseController($controller)
479479
}
480480
$controller['method'] = $r->name;
481481

482-
if ($class = $r->getClosureScopeClass()) {
482+
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
483483
$controller['class'] = $class->name;
484484
} else {
485485
return $r->name;

src/Symfony/Component/Messenger/Handler/HandlerDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(callable $handler, array $options = [])
3737
if (str_contains($r->name, '{closure}')) {
3838
$this->name = 'Closure';
3939
} elseif (!$handler = $r->getClosureThis()) {
40-
$class = $r->getClosureScopeClass();
40+
$class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass();
4141

4242
$this->name = ($class ? $class->name.'::' : '').$r->name;
4343
} else {

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