Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[VarExporter] Generate proxies for static abstract methods
  • Loading branch information
nicolas-grekas committed Dec 21, 2022
commit 47fc4d5c8419c7bb5c9a7a834185c5d7d04cef8d
6 changes: 4 additions & 2 deletions src/Symfony/Component/VarExporter/ProxyHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf
}

foreach ($methodReflectors as $method) {
if ($method->isStatic() || isset($methods[$lcName = strtolower($method->name)])) {
if (($method->isStatic() && !$method->isAbstract()) || isset($methods[$lcName = strtolower($method->name)])) {
continue;
}
if ($method->isFinal()) {
Expand All @@ -145,7 +145,9 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf
$signature = self::exportSignature($method);
$parentCall = $method->isAbstract() ? "throw new \BadMethodCallException('Cannot forward abstract method \"{$method->class}::{$method->name}()\".')" : "parent::{$method->name}(...\\func_get_args())";

if (str_ends_with($signature, '): never') || str_ends_with($signature, '): void')) {
if ($method->isStatic()) {
$body = " $parentCall;";
} elseif (str_ends_with($signature, '): never') || str_ends_with($signature, '): void')) {
$body = <<<EOPHP
if (isset(\$this->lazyObjectReal)) {
\$this->lazyObjectReal->{$method->name}(...\\func_get_args());
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ public function foo2(?\Symfony\Component\VarExporter\Tests\Bar $b): \Symfony\Com

return throw new \BadMethodCallException('Cannot forward abstract method "Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface2::foo2()".');
}

public static function foo3(): string
{
throw new \BadMethodCallException('Cannot forward abstract method "Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface2::foo3()".');
}
}

// Help opcache.preload discover always-needed symbols
Expand Down Expand Up @@ -236,6 +241,8 @@ public function foo1(): ?Bar;
interface TestForProxyHelperInterface2
{
public function foo2(?Bar $b): self;

public static function foo3(): string;
}

class TestSignatureFQ extends \stdClass
Expand Down