M
M
Msim2015-09-20 12:25:07
PHP
Msim, 2015-09-20 12:25:07

What's the point of function &bar()?

I'm reading the php documentation section "Passing by reference" I can't understand from just

<?php
function foo(&$var)
{
    $var++; // 6
}
function &bar()
{
    $a = 5;
    return $a; // 5
}
foo(bar()); // кидаем 5 в foo
?>

I can’t understand why we can’t do without & in front of the function, what does it give at all ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
akarin, 2015-09-20
@Msim

Because it is a link to a "copy" of the object. And it means that it must accept this link (adds 1 to the return).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question