0

Possible Duplicate:
Reference - What does this symbol mean in PHP?

Hi, I was using like

$formCheckbox = $form->addElement('radio',...);
$formCheckbox->setChecked(true);

this was working on windows properly but was not on linux i.e it was not checking the radio button.

so i changed it like

$formCheckbox = **&**$form->addElement('radio',...);
$formCheckbox->setChecked(true);

so i just used & while creating the element. I just wanted to know how does it make a difference. I am using HTML quick forms.

Community
  • 1
  • 1
Hacker
  • 7,798
  • 19
  • 84
  • 154

2 Answers2

1

in this case there is not much of a difference, because php handles objects internally as pointers..

but as long as you do not know what & stands for, don't use it..

a short introduction to pointer:

$a = 10; 
$b = &$a; 
$b = 20; 
echo $a; -> 20 

$a = 10; 
$b = $a; 
$b = 20; 
echo $a; -> 10

so with & you only reference to another variable, instead of creating a new one

sharpner
  • 3,857
  • 3
  • 19
  • 28
1

It is passing the variable as a reference, so that the changes are maintained always.

Check this http://php.net/manual/en/language.references.pass.php

Starx
  • 77,474
  • 47
  • 185
  • 261