Skip to content

Commit 82e1c4b

Browse files
committed
[VarExporter] fix proxy helper when a method returns null
1 parent 825f9b0 commit 82e1c4b

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

ProxyHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public static function exportType(\ReflectionFunctionAbstract|\ReflectionPropert
311311
return '';
312312
}
313313
if (null === $glue) {
314-
return (!$noBuiltin && $type->allowsNull() && 'mixed' !== $name ? '?' : '').$types[0];
314+
return (!$noBuiltin && $type->allowsNull() && !\in_array($name, ['mixed', 'null'], true) ? '?' : '').$types[0];
315315
}
316316
sort($types);
317317

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy;
13+
14+
class Php82NullStandaloneReturnType
15+
{
16+
public function foo(): null
17+
{
18+
return null;
19+
}
20+
}

Tests/ProxyHelperTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\VarExporter\Exception\LogicException;
1616
use Symfony\Component\VarExporter\ProxyHelper;
17+
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\Php82NullStandaloneReturnType;
1718
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\StringMagicGetClass;
1819

1920
class ProxyHelperTest extends TestCase
@@ -188,6 +189,17 @@ public function testCannotGenerateGhostForStringMagicGet()
188189
$this->expectException(LogicException::class);
189190
ProxyHelper::generateLazyGhost(new \ReflectionClass(StringMagicGetClass::class));
190191
}
192+
193+
/**
194+
* @requires PHP 8.2
195+
*/
196+
public function testNullStandaloneReturnType()
197+
{
198+
self::assertStringContainsString(
199+
'public function foo(): null',
200+
ProxyHelper::generateLazyProxy(new \ReflectionClass(Php82NullStandaloneReturnType::class))
201+
);
202+
}
191203
}
192204

193205
abstract class TestForProxyHelper

0 commit comments

Comments
 (0)