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 aeecd29

Browse filesBrowse files
committed
[VarExporter] fix proxy helper when a method returns null
1 parent 202199b commit aeecd29
Copy full SHA for aeecd29

File tree

2 files changed

+28
-6
lines changed
Filter options

2 files changed

+28
-6
lines changed

‎src/Symfony/Component/VarExporter/ProxyHelper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/ProxyHelper.php
+6-6Lines changed: 6 additions & 6 deletions
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() && 'null' !== $type->getName() && 'mixed' !== $name ? '?' : '').$types[0];
315315
}
316316
sort($types);
317317

@@ -357,11 +357,11 @@ private static function exportDefault(\ReflectionParameter $param): string
357357
'parent' => ($parent = $class->getParentClass()) ? '\\'.$parent->name : 'parent',
358358
default => '\\'.$m[2],
359359
}
360-
: fn ($m) => $m[1].match ($m[2]) {
361-
'new', 'false', 'true', 'null', 'self', 'parent' => $m[2],
362-
'NULL' => 'null',
363-
default => '\\'.$m[2],
364-
};
360+
: fn ($m) => $m[1].match ($m[2]) {
361+
'new', 'false', 'true', 'null', 'self', 'parent' => $m[2],
362+
'NULL' => 'null',
363+
default => '\\'.$m[2],
364+
};
365365

366366
return implode('', array_map(fn ($part) => match ($part[0]) {
367367
'"' => $part, // for internal classes only

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,28 @@ 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+
$classCode = <<<PHP
198+
class TestNullStandaloneReturnType
199+
{
200+
public function foo(): null
201+
{
202+
return null;
203+
}
204+
}
205+
PHP;
206+
eval($classCode);
207+
208+
self::assertStringContainsString(
209+
'public function foo(): null',
210+
ProxyHelper::generateLazyProxy(new \ReflectionClass('TestNullStandaloneReturnType'))
211+
);
212+
}
191213
}
192214

193215
abstract class TestForProxyHelper

0 commit comments

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