From:             jonas at skubic dot se
Operating system: Linux
PHP version:      5CVS-2007-10-12 (snap)
PHP Bug Type:     Feature/Change Request
Bug description:  array_slice resets the current array position

Description:
------------
array_slice seems to be resetting the current array position *before*
processing the offset parameter.

This makes it impossible to directly use expressions that use the array
position for the offset parameter.

It would be mildly useful and less surprising if the parameters were
evaluated before altering the array.

Reproduce code:
---------------
$a = range(0, 9);
next($a);
next($a);

$b = array_slice($a, key($a));

print_r($b);

Expected result:
----------------
Array
(
    [0] => 2
    [1] => 3
    [2] => 4
    [3] => 5
    [4] => 6
    [5] => 7
    [6] => 8
    [7] => 9
)


Actual result:
--------------
Array
(
    [0] => 0
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 4
    [5] => 5
    [6] => 6
    [7] => 7
    [8] => 8
    [9] => 9
)


-- 
Edit bug report at http://bugs.php.net/?id=42941&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42941&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42941&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42941&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42941&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42941&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42941&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42941&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42941&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42941&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42941&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42941&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42941&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42941&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42941&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42941&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42941&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42941&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42941&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42941&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42941&r=mysqlcfg

Reply via email to