You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
namespaceApp\Entity;
useApp\Foo;
class X {
publicfunctiona($foo = newFoo) {}
publicfunctionb(DateTimeInterface$date = new \DateTime('2000-01-01T12:00:00+00:00')){}
}
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:
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.
class X {
publicfunctiona($foo = null) { $foo ??= newFoo; }
publicfunction (null|\DateTimeInterface$date = null) { $date ??= new \DateTime('2000-01-01T12:00:00+00:00'); }
}
The text was updated successfully, but these errors were encountered:
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 (#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 generatesgarbage 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.
The text was updated successfully, but these errors were encountered: