From:             [EMAIL PROTECTED]
Operating system: irrelevant
PHP version:      5.3CVS-2007-12-09 (CVS)
PHP Bug Type:     Arrays related
Bug description:  array_slice() length parameter's messed up

Description:
------------
If the length argument fed to array_slice() isn't of PHP type integer,
array_slice() fails silently.

This was broken during Jani's major backporting session from CVS HEAD on
Nov 2nd (i.e. it looks like HEAD's broken this way too). In the 5_2 branch
there's a less clean API but the Z_LVAL_P is explicitly converted to long.

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/array.c?r1=1.308.2.21.2.37.2.5&r2=1.308.2.21.2.37.2.6&pathrev=PHP_5_3

I've a trivial fix for it that involves making the zval length parameter 
a long. It's impossible to tell from the test suite whether this breaks
anything that wasn't broken before (looking at how it's used, I can't see
how it could.) Patch should apply cleanly to HEAD also, apart from the
length initialization (already exists in HEAD but not in 5_3).


Reproduce code:
---------------
Basic, but illustrates the problem:

<?php

$arr = array(1, 2, 3, 4, 5, 6);

var_dump(array_slice($arr, 0, (float)2));
var_dump(array_slice($arr, 0, (int)2));

?>


Expected result:
----------------
array(2) {
  [0]=>
  int(1)
  [1]=>
  int(2)
}
array(2) {
  [0]=>
  int(1)
  [1]=>
  int(2)
}


Actual result:
--------------
array(0) {
}
array(2) {
  [0]=>
  int(1)
  [1]=>
  int(2)
}

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

Reply via email to