We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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


16.0k
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;
}