Bug #72546 [Opn->Nab]: Unexpected implicit cast to number
Edit report at https://bugs.php.net/bug.php?id=72546&edit=1
ID: 72546
Updated by: requinix@php.net
Reported by: account at friends-of-bytes dot com
Summary: Unexpected implicit cast to number
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: All
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
String keys that are valid integers are converted to integers. That "0" key is actually
just 0.
http://php.net/manual/en/language.types.array.php#language.types.array.syntax.array-func
Previous Comments:
------------------------------------------------------------------------
[2016-07-05 12:13:37] account at friends-of-bytes dot com
Description:
------------
There is an array with 3 values. These values are referenced by 3 string-keys.
It seems that there is a implicit cast with the index '0' to int, so that
(0 == "any string") is always true.
but:
('0' == "any string") is always false, so there is no reason for that result.
Test script:
---------------
$kat['test'] = "a";
$kat['0'] = "b";
$kat['1'] = "c";
foreach ($kat as $key => $val)
{
if ($key != "test")
$i++;
}
echo $i;
Expected result:
----------------
2
Actual result:
--------------
1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72546&edit=1
Thread (2 messages)