Fork me on GitHub

Question about references and use of '&' in assignment  Bottom

  • Hi,

    I was looking through the PN code and found the following which doesn't quite seem right: in pnAPI.php the following function is defined:

    Code

    function &pnDBGetTables()


    The in (for example) pnMod.php (and other places) this function is typically invoked like this:

    Code

    $pntable =& pnDBGetTables();


    So the declaration of the function defines that a reference is returned from said function. Then when you're actually using the function, you're again explicitly assigning a reference to the resulting variable. It seems that one of the '&' (reference operators) is superflous here: either you define it at the function declaration or you use it in the invocation/assignment statement.

    What is the correct way of doing this? Am I misunderstanding something here?

    Thanks
    Lobita
  • Anybody know the definitive answer to this?

    Thanks
  • It is correct read this:

    http://us3.php.net/manual/en/language.references.return.php

    this is the way PHP passes references from a function …
    without the '&' it would assign a copy of the returned variable...

    by the way this is not C++ .... all variables are in a symbol table
    no memory addresses are used directly

    Alexan
  • 0 users

This list is based on users active over the last 60 minutes.