Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does & sign mean in front of a variable?

Tags:

php

punbb

I'm 'dissecting' PunBB, and one of its functions checks the structure of BBCode tags and fix simple mistakes where possible:

function preparse_tags($text, &$errors, $is_signature = false)

What does the & in front of the $error variable mean?

like image 443
john mossel Avatar asked Nov 14 '10 00:11

john mossel


People also ask

What does the fox say Meaning?

The idea for“The Fox (What Does the Fox Say?)” was for it not to be hit. Instead, the brothers were going to use the footage of the song on their show in Norway to prove what absolute failures they were in the music business.

What is this song Google?

Ask Google Assistant to name a song On your phone, touch and hold the Home button or say "Hey Google." Ask "What's this song?" Play a song or hum, whistle, or sing the melody of a song. Hum, whistle, or sing: Google Assistant will identify potential matches for the song.

What does the fox say for real?

One of the most common fox vocalizations is a raspy bark. Scientists believe foxes use this barking sound to identify themselves and communicate with other foxes. Another eerie fox vocalization is a type of high-pitched howl that's almost like a scream.


1 Answers

It means pass the variable by reference, rather than passing the value of the variable. This means any changes to that parameter in the preparse_tags function remain when the program flow returns to the calling code.

function passByReference(&$test) {
    $test = "Changed!";
}

function passByValue($test) {
    $test = "a change here will not affect the original variable";
}

$test = 'Unchanged';
echo $test . PHP_EOL;

passByValue($test);
echo $test . PHP_EOL;

passByReference($test);
echo $test . PHP_EOL;

Output:

Unchanged

Unchanged

Changed!

like image 107
Andy Avatar answered Oct 11 '22 23:10

Andy