Answer the question
In order to leave comments, you need to log in
Memory usage in php when passing input parameters to a method?
Hello. Question for professionals.
What is better to pass to a method, an entire object or an attribute, provided that only 1 attribute is used?
For example:
public function getChildren($parent)
{
return Page::where('parent_id', '=', $parent->id);
}
public function getChildren($parentId)
{
return Page::where('parent_id', '=', $parentId);
}
Answer the question
In order to leave comments, you need to log in
In fact, a pointer to an object is passed to the function. There won't be much difference.
It is better not to drive extra data in calls. Pass only the Id if it is required.
php.net/manual/en/functions.arguments.php
If you are using Laravel, then you should explicitly set up Relations on your models.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question