A
A
Annywebart2015-12-14 04:49:45
PHP
Annywebart, 2015-12-14 04:49:45

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);
}

or
public function getChildren($parentId)
{
  return Page::where('parent_id', '=', $parentId);
}

Does it somehow affect the memory consumption and the speed of the script?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2015-12-14
@Annywebart

In fact, a pointer to an object is passed to the function. There won't be much difference.

A
Alexander, 2015-12-14
@bIbI4k0

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

M
Mikhail Osher, 2015-12-14
@miraage

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 question

Ask a Question

731 491 924 answers to any question