Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Johannes Schlüter:
More on references
Feb 23, 2016 @ 10:48:31

Johannes Schlüter has continued his series of posts with this second part looking more at reference handling in PHP (how they're handled "behind the scenes" that is).

In a few different places I saw comments about my last blog post about references and performance where commentators noted that my example was pointless. Which of course is true and to some degree the point.

I read a lot of PHP code and from time to time I see people with a non-PHP background (or otherwise influenced) putting references everywhere they pass arrays or such in order to prevent copies. I knew this was a bad practice in PHP 5 and wanted to verify this in PHP 7.

In the post he talks about passing references to methods and how it can lead to less clarity in the resulting code. He also wonders about the situation when you don't actually want to modify the variable passed in and making copies (losing any performance gain). He suggests that using references should only come when you know exactly how the value will be used in the method, not casually or just for performance reasons.

tagged: references php5 clear code php7 copy

Link: http://schlueters.de/blog/archives/181-More-on-references.html