Why would one want to pass primitive-type parameters by reference in PHP?
<p>One thing that's always bugged me (and everyone else, ever) about PHP is its inconsistency in function naming and parameters. Another more recent annoyance is its tendency to ask for function parameters by reference rather than by value.</p>

<p>I did a quick browse through the PHP manual, and found the function <code>sort()</code> as an example. If I was implementing that function I'd take an array by value, sort it into a new array, and return the new value. In PHP, <code>sort()</code> returns a boolean, and modifies the existing array.</p>

<p>How I'd like to call <code>sort()</code>:</p>

<pre><code>$array = array('c','a','b');
$sorted_array = sort($array);
</code></pre>

<p>How PHP wants me to call <code>sort()</code>:</p>

<pre><code>$array = array('c','a','b');
sort($array);
$sorted_array = $array;
</code></pre>

<p>And additionally, the following throws a fatal error: <code>Fatal error: Only variables can be passed by reference</code></p>

<pre><code>sort(array('c','a','b');
</code></pre>

<p>I'd imagine that part of this could be a legacy of PHP's old days, but there must have been a reason things were done this way. I can see the value in passing an object by reference ID like PHP 5+ does (which I guess is sort of in between pass by reference and pass by value), but not in the case of strings, arrays, integers and such.</p>

<p>I'm not an expert in the field of Computer Science, so as you can probably gather I'm trying to grasp some of these concepts still, and I'm curious as to whether there's a reason things are set up this way, or whether it's just a leftover.</p>
