0

Short question:

function Foo(&$FooParam)
{
...
}

Foo(&$Bar);

How to keep this code and make it work in PHP 5.4?

Longer description:

I have quite a lot of PHP code in which I used a notation pattern from C# - mark reference parameters at declaration AND function call. It makes code more readable and prevents mistakes when refactoring code. Now PHP from 5.4 reports this as unsupported call-time pass by reference, which I believe is incorrect (according to php.net, the prohibition of this feature in 5.4 was meant against the caller changing semantics of function parameters. It clearly does not apply in this case).

I still see the code with & at function declaration and call as more readable and want to use it. Is there any way how to make it work in PHP 5.4? If not, please feel free to add some reasoning which would convince me that this C# practice is wrong and I should rewrite all the code so that it will be 5.4-compatible.

Edit: I have read some eight or ten questions on similar topic and the difference is I'm not asking "how to fix code" but "how not to fix code". If there is really no way how to make it working, please state your oppinion on why is it decided to be this way or why I should prefer this "new" way of writing code which (I think) is worse than the "old" way.

hakre
  • 193,403
  • 52
  • 435
  • 836
Jan Svab
  • 1
  • 3
  • possible duplicate of [PHP 5.4 Call-time pass-by-reference - Easy fix available?](http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available) – mbeckish Aug 06 '12 at 15:47
  • Altough on the same topic, I think my question is different. I know the "easy fix" - remove the & in function call. But I don't want to do it. – Jan Svab Aug 06 '12 at 19:43
  • I think the takeaway from all of the other posts on this subject is no, there is no way around it. – mbeckish Aug 06 '12 at 19:48

0 Answers0