为什么要在PHP中通过引用传递原始类型参数?

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.

I did a quick browse through the PHP manual, and found the function sort() 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, sort() returns a boolean, and modifies the existing array.

How I'd like to call sort():

$array = array('c','a','b');
$sorted_array = sort($array);

How PHP wants me to call sort():

$array = array('c','a','b');
sort($array);
$sorted_array = $array;

And additionally, the following throws a fatal error: Fatal error: Only variables can be passed by reference

sort(array('c','a','b');

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.

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.

The main reason is that PHP was developed by C programmers, and this is very much a C-programming paradigm. In C, it makes sense to pass a pointer to a data structure you want changed. In PHP, not so much (Among other things, because references are not the same as a pointer).

I believe this is done for speed-reason.
Most of the time you need the array you are working on to be sorted, not a copy.

If sort should have returned a new copy of the array then for each time you call sort(); the PHP engine should have copied the array into new one (lowering speed and increasing space cost) and you would have no way to control this behaviour.

If you need the original array to be not sorted (and this doesn't happen so often) then just do:

$copy = $yourArray;
sort($yourArray);