doctrine / common

Doctrine Common
https://www.doctrine-project.org/projects/common.html
MIT License
5.79k stars 294 forks source link

ProxyGenerator turns double quoted default values into single quoted default values #987

Closed ampaze closed 2 years ago

ampaze commented 2 years ago

Using PHP 8.1 and doctrine/common 3.4.1

the method in my entity

public function formatAsString(string $rowDelim = "\n"): string
{
}

is turned in to

public function formatAsString(string $rowDelim = '\n'): string
{
}

in the proxy.


Fyi:

This is the version that 3.3.1 generates

public function formatAsString(string $rowDelim = '
'): string
{
}
malarzm commented 2 years ago

This might be a bug in how PHP is generating default values as 3.4.x started to relying on that. I'll try to have it reproduced later

nicolas-grekas commented 2 years ago

This looks like a PHP issue to me, I opened https://github.com/php/php-src/issues/9622 There might be a workaround, to be discovered.

malarzm commented 2 years ago

@ampaze as a workaround you could define your method like this:

public function formatAsString(string $rowDelim = \PHP_EOL): string
{
}

referencing global consts is working good enough with 3.4.1

stof commented 2 years ago

@malarzm \PHP_EOL is not the same than "\n" though

malarzm commented 2 years ago

@stof you're right,I thought it was just "good enough" to mention :)