Closed Amunak closed 2 years ago
Well I didn't search correctly, as this should probably be in doctrine/common and there's already a bug report for the same thing, though older version (doctrine/common#961).
Transferring to doctrine/common
(again lol) then
Duplicate of #961
Bug Report
Summary
As of PHP 8.1 it's possible to use objects as default values in properties, so we can use the shorthand
function method($foo = new Bar)
. The proxy generator doesn't know how to deal with this and generates garbage in the signature instead of simply passing the definition over.Current behavior
Properties with objects as default value have invalid signature in proxy classes. This results in
Compile Error: Constant expression contains invalid operations
.How to reproduce
Given entity X:
There will be the following proxy class generated:
Note how it also gets the namespaces wrong in addition to attempting to instance(?) the object and fill it with data from time of the proxy generation (which is definitely wrong).
Expected behavior
The proxy generator generates a parameter where it simply re-uses the default value signature when an object is used as default parameter, only making sure the class uses absolute path.
I would expect the proxy class to look more like this:
Current workaround
Obviously this isn't a huge deal since one can simply assign the objects in the method body like always, but it's not optimal since that may force you to change the signature to allow for null values, which is slightly more ambiguous than the alternative.