I've noticed some inconsistencies in the PHP manual; a number of core function signatures are documented to accept arguments by reference, however they accept arguments by value.
I posted a more specific question previously, and @cweiske provided a great answer (with reference to the pertinent PHP source) however these inconsistencies appear to be more rampant.
There are a number of functions that are affected by this (I'll update this list as warrants; also note, these tests were done in an error_reporting(-1)
environment)
- http://www.php.net/manual/en/function.current.php
- This was already discussed at the linked question
- http://www.php.net/manual/en/function.key.php
- This was already discussed at the linked question
http://www.php.net/manual/en/function.array-replace-recursive.phparray
array_replace_recursive
( array
&$array
, array
&$array1
[, array
&$
... ] )
- Accepts arguments
$array
,$array1
, etc., by value. This has been corrected.
- http://www.php.net/manual/en/function.array-multisort.php
bool
array_multisort
( array
&$arr
[, mixed
$arg
=
SORT_ASC
[, mixed
$arg
=
SORT_REGULAR
[, mixed
$
... ]]] )
- Accepts arguments
$arr
, etc., by value. This should throw an error, as it won't do anything if the argument isn't a variable.
Now I'm concerned, not because I'm being anal about the documentation, but because I fear that PHP devs are on the fence about the implementation details of these functions (or something equally unreliable)
I use array_replace_recursive()
for instance, to take an array argument, and apply it against another array containing defaults. Some of my codebase has taken advantage of this inconsistency, to simply do:
$values = array_replace_recursive(array(
'setting_1' => array(
'sub-setting_1' => '',
'sub-setting_2' => '',
'sub-setting_3' => '',
),
'setting_2' => array(
'sub-setting_1' => 0,
'sub-setting_2' => 0,
),
'setting_3' => true,
), $values);
Thus producing a properly formatted array (to get around gratuitous isset()
calls)
Should I be concerned with this? I'm thinking about submitting a documentation related bug request, but I'm first curious if anyone on SO (looking in your direction @cweiske) has insight on why this has been done.