What is the purpose of using "&" in passing parameters to PHP functions?

Asked

Viewed 40 times

5

Good staff,

Following pointer logic I came across the following problem. If you run the function below using "&" the PHP memory consumption goes up, it should not be the other way around since I am passing the same variable instead of passing a reference?

$teste = 'teste';

function test($teste) {} // consome menos memória

or

function test(&$teste) {} // consome mais memória

My test ran in PHP version 7.1.

Thank you

  • 1

    @Maniero , I do not think that this answer addresses this question in terms of performance/consumption , I think this question is pertinent and I do not believe that in php we have any that explains why "PHP memory consumption goes up, it shouldn’t be the other way around since I’m passing the same variable instead of passing a reference?"

  • @Miguel is true, but then I don’t know if there is a logical and factual explanation for this, even we don’t know how the test was done. Only with the code posted has no way to see if the memory consumption has changed reliably. So either it would not be clear or it can not be reproduced.

  • @Maniero as far as we know AP tested, "...PHP’s memory consumption goes up". I confess that I am curious but I do not have time now to spend on research/tests. But in fact it must be difficult to come up with a php-focused explanation for this

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.