From:             postings-php-bug at hans-spath dot de
Operating system: Irrelevant
PHP version:      4.3.3
PHP Bug Type:     Documentation problem
Bug description:  wrong array_splice() equivalents given

Description:
------------
The documentation for array_splice gives some "equivalents" for special
cases in Table 1.

These are WRONG.

array_pop and array_shift return single *VALUES*, array_splice returns an
array.
array_pop and array_shift do NOT perform the same action.
In "$a[$x] = $y", $x is a KEY.
In array_splice($input, $x, 1, $y), $x is a POSITION.

Reproduce code:
---------------
D:\PHP>cat test\array_splice.php
<?
$tests = array(
        'array_shift($input)',
        'array_pop($input)',
        'array_splice($input, -1)',
        '$a[$x] = $y',
        'array_splice($input, $x, 1, $y)'
);

foreach( $tests as $test )
{
        $input = array(
                '1st' => 'first element',
                2     => 'second element',
                '3rd' => 'third element'
        );
        $x = 2;
        $y = 'replaced element';

        echo "\n$test\n";
        eval( "\$z = $test ;" );
        var_dump( $z );
}

Expected result:
----------------
*I* expect it to work as it works, but people misled by the documentation
could expect something else.

Actual result:
--------------
D:\PHP>4.3.3\php-cli.exe -n test\array_splice.php

array_shift($input)
string(13) "first element"

array_pop($input)
string(13) "third element"

array_splice($input, -1)
array(1) {
  ["3rd"]=>
  string(13) "third element"
}

$a[$x] = $y
string(16) "replaced element"

array_splice($input, $x, 1, $y)
array(1) {
  ["3rd"]=>
  string(13) "third element"
}

-- 
Edit bug report at http://bugs.php.net/?id=25489&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25489&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25489&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25489&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25489&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25489&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25489&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25489&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25489&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25489&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25489&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25489&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25489&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25489&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25489&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25489&r=gnused

Reply via email to