#46576 [NEW]: Adding to end of array - strange behaviour
| From: | geo at vzemibg dot com | Date: | Fri, 14 Nov 2008 17:56:06 +0000 |
| Subject: | #46576 [NEW]: Adding to end of array - strange behaviour | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-130968@lists.php.net to get a copy of this message | ||
From: geo at vzemibg dot com
Operating system: CentOS
PHP version: 5.2.6
PHP Bug Type: Arrays related
Bug description: Adding to end of array - strange behaviour
Description:
------------
I am submitting what in my view is uncorrect behaviour of the [] operator
for arrays. It is a special case when the last element of the array is
removed with unset() and then a new element is added using the arrname[] =
xxxx syntax.
Reproduce code:
---------------
$teststring = "let's test this";
$testarr = explode(' ', $teststring);
print_r($testarr);echo "<br />";
unset($testarr[2]);
print_r($testarr);echo "<br />";
$testarr[] = 'new';
print_r($testarr);
Expected result:
----------------
Array ( [0] => let's [1] => test [2] => this )
Array ( [0] => let's [1] => test )
Array ( [0] => let's [1] => test [2] => new )
Actual result:
--------------
Array ( [0] => let's [1] => test [2] => this )
Array ( [0] => let's [1] => test )
Array ( [0] => let's [1] => test [3] => new )
--
Edit bug report at http://bugs.php.net/?id=46576&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46576&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46576&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46576&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=46576&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46576&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=46576&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=46576&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=46576&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=46576&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=46576&r=support
Expected behavior: http://bugs.php.net/fix.php?id=46576&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=46576&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=46576&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=46576&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46576&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46576&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=46576&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=46576&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=46576&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=46576&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=46576&r=mysqlcfg