list() is behaving logical and weird at the same time
list($a, $b) = array(1, 2, 3, 4);
What direction will list start processing the array? You'd expect that it'd be left to right and that's right:
$a = 1,
$b = 2. But where it gets confusing:
list($a, $a) = array(1, 2, 3, 4);
Well, we already know
list will only consider 1 and 2. So first 1 gets assigned to
$a and then 2 gets assigned and that's where our story ends, right? After all, the second
$a is where
$b used to be, right? Wrong. The manual warns you
list() assigns the values starting with the right-most parameter.
$a becomes 2 and then 1. And so
$a becomes 1.
This is where writing a manual becomes hard -- are you going to add a counter-warning that the slicing does behave normally? What kind of warning is that, anyways: "there is nothing to see here, move on". Do you just let this slip and hope people get that the abscence of the warning means there's nothing to be warned about? Or in the light of a strange behavior normal behavior merits a warning?
Actually, if you want to confuse someone at a tech interview, just throw
list($a, $a) = array(1, 2, 3, 4); and point out how 1, 2, 3, 4 are all possible depending on where list starts processing the left and the right side -- if the left side is processed from right-to-left why not the right side too? (Because it makes no sense to do that!).