Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Passing values by Reference

Hi All,

Is it possible to pass values by Reference in Phalcon? This simple code does not work :

$x = 10;
echo $x;
&$x = 11;
echo $x; // should be 11 but does not work in phalcon


12.3k
Accepted
answer

of course it works, phalcon is just the framework, but other than that you're using plain php. And the way you wrote it will return an error

function indexAction()
{
  $x = 10;
  echo $x; // 10

  $this->passByReference($x);
  echo $x; // 11 
}

public function passByReference(&$x) {
  $x = 11;
}