Doc #55069 [NEW]: slice_array() does not always reset()?

From: Date: Wed, 29 Jun 2011 17:20:29 +0000
Subject: Doc #55069 [NEW]: slice_array() does not always reset()?
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-6759@lists.php.net to get a copy of this message
From: Operating system: Mac OS X 10.6.7 PHP version: 5.3.6 Package: *General Issues Bug Type: Documentation Problem Bug description:slice_array() does not always reset()? Description: ------------ --- From manual page: http://www.php.net/function.array-slice%23Description --- array_slice() should reset() the array pointer; however, I've observed the following: // MySQL formatted date $string = '2011-06-30 02:49:24'; // Regex to convert date to parts, with time optional preg_match('/^(\d{4})-(\d{2})-(\d{2})( (\d{2}):(\d{2}):(\d{2})\.?\d?)?$/', $string, $parts); $output = array_slice($parts, 0, 4) + array_slice($parts, 5); print_r($output); Basically, this was just a quick, dirty way to get date/time values into parts, but ignore the match of just the time ($parts[4]). I expected to get: Array ( [0] => 2011-06-30 02:49:24 [1] => 2011 [2] => 06 [3] => 30 [4] => 02 [5] => 49 [6] => 24 ) But I always got: Array ( [0] => 2011-06-29 21:49:24 [1] => 2011 [2] => 06 [3] => 29 ) However, this does produce the expected result: $array = array_slice($parts, 0, 4) + array_slice($parts, 1); print_r($array); Note that the second slice starts the slice at index 1 and not 5 as I'd expect if index() had been reset by first call to array_slice. Apparently, the reset() is called only after completion of the full statement and not by the function itself? Not sure if this is a bug or an undocumented feature. My example is a bit silly, I know, as I should have array_spliced() in this case, but the output Test script: --------------- // MySQL formatted date $string = '2011-06-30 02:49:24'; // Regex to convert date to parts, with time optional preg_match('/^(\d{4})-(\d{2})-(\d{2})( (\d{2}):(\d{2}):(\d{2})\.?\d?)?$/', $string, $parts); $output = array_slice($parts, 0, 4) + array_slice($parts, 5); print_r($output); -- Edit bug report at https://bugs.php.net/bug.php?id=55069&edit=1 -- Try a snapshot (PHP 5.2): https://bugs.php.net/fix.php?id=55069&r=trysnapshot52 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55069&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55069&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=55069&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55069&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=55069&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=55069&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=55069&r=needscript Try newer version: https://bugs.php.net/fix.php?id=55069&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=55069&r=support Expected behavior: https://bugs.php.net/fix.php?id=55069&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=55069&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=55069&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=55069&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55069&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=55069&r=dst IIS Stability: https://bugs.php.net/fix.php?id=55069&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=55069&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=55069&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=55069&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=55069&r=mysqlcfg

« previous php.doc.bugs (#6759) next »