-
-
Notifications
You must be signed in to change notification settings - Fork 505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undefined property error from proxy when EmbedOne field is not set #2080
Comments
@Frederick888 could you please report an issue to https://github.com/Ocramius/ProxyManager as it seems to be a shortcoming in the proxying mechanism itself? For the time being you may consider using a getter method that should work just fine as it won't utilize magic |
@Frederick888 out of curiosity, does the error appear when changing property visibility to |
No problem. But honestly I've got no idea what OOP proxies are... What would be an appropriate title for the issue there?
You meant a getter in my own model? It's already got one in public function __get($name)
{
$accessor = 'get_' . $this->snakeCase($name);
if (method_exists($this, $accessor)) {
return $this->$accessor();
}
return $this->$name ?? null;
}
This time the undefined public static function staticProxyConstructor($initializer)
{
static $reflection;
$reflection = $reflection ?? $reflection = new \ReflectionClass(__CLASS__);
$instance = $reflection->newInstanceWithoutConstructor();
unset($instance->address, $instance->excludedFromArray);
\Closure::bind(function (\App\Doctrine\BaseModel $instance) {
unset($instance->preserveOriginalName);
}, $instance, 'App\\Doctrine\\BaseModel')->__invoke($instance);
$instance->initializerc3072 = $initializer;
return $instance;
} |
@Frederick888 something like "Undefined property error for public property and __get" should do. Also you can link to this issue, but I'm sure @Ocramius will either know what to do or what questions to ask :) |
Assigning a bug label for now, I hopefully may have time in the coming days to take a look at this as it's quite severe. |
Closing as #2082 was merged |
BC Break Report
Summary
When an EmbedOne field is not set in database, it now causes an
Undefined property
error.Previous behavior
Previously in 1.2.x the field was simply left
null
.Current behavior
An
Undefined property
is caused by generated proxy__get($name)
method.How to reproduce
For instance, I've got 2 models
Lab
andAddress
:Now if I insert a new
Lab
document without touching theaddress
field, it's also not set in the database as it used to be. However, when I retrieve the document, in the hydrator it's got...and in the proxy it's got
Since the
address
field is not set in the hydrator, when the proxy tries to get its valuereturn $this->$name
it causes anUndefined property
error.PS: Not sure whether it's relevant but
BaseModel
isThe text was updated successfully, but these errors were encountered: