Skip to content

Commit a0587f6

Browse files
authored
Merge pull request #992 from doctrine/3.4.x-merge-up-into-3.5.x_9eYIZZDG
Merge release 3.4.2 into 3.5.x
2 parents 8a645b3 + 609c3a7 commit a0587f6

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

src/Proxy/ProxyGenerator.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use function interface_exists;
3737
use function is_callable;
3838
use function is_dir;
39+
use function is_scalar;
3940
use function is_string;
4041
use function is_writable;
4142
use function lcfirst;
@@ -1122,7 +1123,7 @@ private function getParameterDefaultValue(ReflectionParameter $parameter)
11221123
return '';
11231124
}
11241125

1125-
if (PHP_VERSION_ID < 80100) {
1126+
if (PHP_VERSION_ID < 80100 || is_scalar($parameter->getDefaultValue())) {
11261127
return ' = ' . var_export($parameter->getDefaultValue(), true);
11271128
}
11281129

tests/Common/Proxy/PHP81NewInInitializers.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@ public function arrayInDefault(array $foo = [new \DateTimeImmutable('2022-08-22
2323

2424
}
2525

26-
public function constInDefault(string $foo = ConstProvider::FOO): void
26+
public function scalarConstInDefault(string $foo = ConstProvider::FOO_SCALAR): void
27+
{
28+
29+
}
30+
31+
public function constInDefault(array $foo = ConstProvider::FOO): void
32+
{
33+
34+
}
35+
36+
public function globalEolInDefault(string $foo = \PHP_EOL): void
37+
{
38+
39+
}
40+
41+
public function specialCharacterInDefault(string $foo = "\n"): void
2742
{
2843

2944
}

tests/Common/Proxy/ProxyGeneratorTest.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,22 @@ public function testPhp81NewInInitializers()
602602
);
603603

604604
self::assertStringContainsString(
605-
'constInDefault(string $foo = \Doctrine\Tests\Common\Util\TestAsset\ConstProvider::FOO): void',
605+
'scalarConstInDefault(string $foo = \'foo\'): void',
606+
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NewInInitializers.php')
607+
);
608+
609+
self::assertStringContainsString(
610+
'constInDefault(array $foo = \Doctrine\Tests\Common\Util\TestAsset\ConstProvider::FOO): void',
611+
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NewInInitializers.php')
612+
);
613+
614+
self::assertStringContainsString(
615+
"globalEolInDefault(string \$foo = '\n'): void",
616+
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NewInInitializers.php')
617+
);
618+
619+
self::assertStringContainsString(
620+
"specialCharacterInDefault(string \$foo = '\n'): void",
606621
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NewInInitializers.php')
607622
);
608623
}

tests/Common/Util/TestAsset/ConstProvider.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66

77
class ConstProvider
88
{
9-
public const FOO = 'foo';
9+
public const FOO = ['foo'];
10+
public const FOO_SCALAR = 'foo';
1011
}

0 commit comments

Comments
 (0)