Skip to content

Commit 6fd1794

Browse files
committed
[VarExporter] fix proxy helper when a method returns null
1 parent 202199b commit 6fd1794

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Symfony/Component/VarExporter/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() && $type->getName() !== 'null' && 'mixed' !== $name ? '?' : '').$types[0];
315315
}
316316
sort($types);
317317

src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,24 @@ public function testCannotGenerateGhostForStringMagicGet()
188188
$this->expectException(LogicException::class);
189189
ProxyHelper::generateLazyGhost(new \ReflectionClass(StringMagicGetClass::class));
190190
}
191+
192+
/**
193+
* @requires PHP 8.2
194+
*/
195+
public function testNullStandaloneReturnType()
196+
{
197+
$classWithNullReturnType = new class{
198+
public function foo(): null
199+
{
200+
return null;
201+
}
202+
};
203+
204+
self::assertStringContainsString(
205+
'public function foo(): null',
206+
ProxyHelper::generateLazyProxy(new \ReflectionClass($classWithNullReturnType))
207+
);
208+
}
191209
}
192210

193211
abstract class TestForProxyHelper

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