If the resource exists then there is a reason for its use.
Probably the recommendation not to use is to try optimizations. This can be considered premature optimization, mainly because PHP already does optimization pass the argument by reference when this is useful even though it has no mention to pass by reference. Of course, if the expected semantics are not referenced, optimization is about using the copy- on-write . So an attempt to optimize by passing something by reference may even disrupt this optimization.
I will not repeat what I always say that micro-optimizing PHP is not usually the most productive thing.
Although rare, there may be the problem of getting referrals for references and losing control if overused.
But if the intention is really to go by reference, if you have a good reason to use it, there is no problem. And in fact, it is seldom necessary. Almost always when someone thinks about using a reference, they are probably thinking about performance or not finding a better way to do the same, so the use is wrong.
Almost always when the intention is to go by reference, you should do this with a type that is naturally passed on with this semantics.
But for everything there is reason to use or not to use. Like everything else, use really to know what you're doing, if you understand all the implications. And do not use if you do not know why you are using it. Not everyone understands what happens to the data when you use a reference. It's not so complicated, but it's easy to forget that you're manipulating a reference and this has consequences in every writing done on that variable.
I understand the use of the reference in the argument that is different from the parameter . But after Zuul's response I paid more attention to the example and saw something different.
You have problem yes.
One thing is to say that you want to pass an argument by reference, depending on the title of the question, another thing is to ask in the parameter that the argument is implicitly received by reference. That is, who calls does not know that is passing by reference something that should be passed by value under normal conditions.
But what kind of language does this allow? PHP, of course. And the maintainers of language have been overcome. I did not know but the newer versions made the problem worse.
Making the caller use a reference is not so bad. Think carefully. If the caller is explicitly passing by reference, does he know that this semantic is being used, what harm can it cause? At most, what I mentioned, the programmer does not know what this means.
Then a possibility of language improvement would be to force the call to use the reference in the argument when the parameter was noted to be received by reference.
But what did she do? Prohibited to do this: D This ... is ... in-critical!
There the new versions made the reference impractical for those who like organized, expressive code, code that indicates their intention and does not give rise to the wrong interpretation. Since passing by reference is now implicitly use it if you want to create confusion.
This would be the "right":
<?php
function something(&$string)
{
$string .= 'B';
}
$variavel = 'A';
something(&$variavel); //<============ Note aqui
echo $variavel;//Irá mostrar "AB"
But this does not compile. The certainty was this to be obligatory. So the "signature" of the call beats with the signature of the function definition. That is, both have the reference.
I'm not saying that careful programmers can not program using implicit references without causing problems. But programmers care about programming in C in Assembly :) What I mean is that PHP should not be a language where you have to have this kind of concern. In fact this specifically, nor C has. In C you have to be explicit.
Of course I'm not talking about the types that are known to be for reference, there is a programmer's knowledge that is easier to understand.
In conclusion, it has legibility problem, yes, but it does not mean that it should not be used at all. I would really avoid it and when I had to use it, I would document it blatantly.