Doc #60661 [Opn->Csd]: array_shift converts string-encapsulated numbers into numbers
| From: | frozenfire@php.net | Date: | Tue, 24 Jan 2012 22:52:33 +0000 |
| Subject: | Doc #60661 [Opn->Csd]: array_shift converts string-encapsulated numbers into numbers | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-7853@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60661&edit=1
ID: 60661
Updated by: frozenfire@php.net
Reported by: jwege at gmx dot net
Summary: array_shift converts string-encapsulated numbers
into numbers
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Arrays related
PHP Version: 5.3.8
-Assigned To:
+Assigned To: frozenfire
Block user comment: N
Private report: N
New Comment:
phpmpan at mpan dot pl is correct. This is expected behaviour that is well-
documented.
Previous Comments:
------------------------------------------------------------------------
[2012-01-10 10:17:21] asd_wte at yahoo dot com
cannot replicate the error. i get the following:
Array ( [_] => blank dummy [01] => one [10] => ten [20] => twenty ) ten Array (
[01] => one [0] => ten [1] => twenty ) ten twenty
must be a misconfigured php.ini
------------------------------------------------------------------------
[2012-01-06 02:03:33] phpmpan at mpan dot pl
array_shift has nothing to do with this. Keys are integers immedietly after assignment.
Use var_dump instad of print_r.
This behaviour is consistent with documentation. [1] clearly states that:
"If a key is the standard representation of an integer,
it will be interpreted as such."
[1] http://pl.php.net/manual/en/language.types.array.php
------------------------------------------------------------------------
[2012-01-04 22:24:43] jwege at gmx dot net
Description:
------------
---
From manual page: http://www.php.net/function.array-shift#refsect1-function.array-shift-seealso
---
Having an associative array where the keys are number-strings (enclosed in quotes as strings - see
example), this strings get converted into numbers when using array_shift().
This is a severe bug!
Test script:
---------------
$a["_"] = "blank dummy";
$a["01"] = "one";
$a["10"] = "ten";
$a["20"] = "twenty";
print_r( $a );
echo $a["10"] . "\n";
array_shift( $a );
print_r( $a );
echo $a["10"] . "\n"; // THIS PRODUCES AN UNDEFINED INDEX ERROR
echo $a["20"] . "\n"; // THIS PRODUCES AN UNDEFINED INDEX ERROR
echo $a[0] . "\n"; // THIS SHOULD PRODUCE AN ERROR BUT SHOWS THE VALUE
echo $a[1] . "\n"; // THIS SHOULD PRODUCE AN ERROR BUT SHOWS THE VALUE
Expected result:
----------------
I expect that the line
echo $a["10"] . "\n";
will produce "ten" as an output, also echo $a["20"] . "\n"; should
output "twenty".
Actual result:
--------------
Notice: Undefined index: 10 in [test] on line 13
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60661&edit=1