-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
[5.2] Allowed Memory size exhaused when accessing undefined index in toArray #14627
Comments
You are just running out of memory when calling |
No, it's a bug. I don't know if it's coming out of Laravel or PHP itself, but it's a bug, 100% positive. This issue showed because I was treating pivot values while serializing a plain object. It should throw me an undefined index error. To fix this issue, i had to ensure to never try to serialize this plain object, and only serialyze it as a relation. As an example : Which is totally normal, but the espected error was |
I don't get it, what is this method?
|
Your examples are not the same thing.
While Try: User::with(['posts' => function ($query) {
$query->take(1);
}])->where('id', '=', 1)->get()->toArray(); This should limit the number of posts you get. If you still get @themsaid I think he is overriding the default behavior of |
@themsaid : @TomKita : The problem is : I do not know if that is a laravel bug or my specific version of php, and i'll try to reproduce it again. But this is clearly a bug. |
Just tested with |
Sorry, just to clarify you did something like this |
No, i did |
If you remove the overridden method from your Post model and call |
No |
I finally find my problem: Errors are correctly thrown and written in laravel log, although, as i'm building a private REST api, I was encoding exception in JSON, which may consume too much memory (maybe circular references ?). Removing trace from the exception resolved my problem. |
Hey !
Succeed to reproduce and isolate a curious bug :
When I try to access an undefined index, it crash and throw "Allowed Memory size exhaused"
Here is the reproduceable bug :
public function toArray() { $buffer = parent::toArray(); dd($buffer['random']); return $buffer; }
Neither of
isset()
norempty()
worked for me(PHP 7.0.1 / Debian 8.4)
Regards,
Robin
The text was updated successfully, but these errors were encountered: