Useful example of passing by reference

The following is a function from the PmWiki Engine » (pmwiki.php).

function SDV(&$v,$x)
{
        if (!isset($v))
        {
                $v = $x;
        }
}

This checks to see if $v is in use and if not it sets $v to the value of $x.

Passing by reference allows you to work on a variable while modifying it at the same time.

It reminds me of mogrify and convert from the ImageMagick libraries. With convert, you have to specify an input file and a different output file, whereas mogrify takes a file as input and modifys it directly leaving you with the same file, but modified.

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.