Bug #72546 [NEW]: Unexpected implicit cast to number

From: Date: Tue, 05 Jul 2016 12:13:38 +0000
Subject: Bug #72546 [NEW]: Unexpected implicit cast to number
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202064@lists.php.net to get a copy of this message
From:             account at friends-of-bytes dot com
Operating system: All
PHP version:      Irrelevant
Package:          *General Issues
Bug Type:         Bug
Bug description:Unexpected implicit cast to number

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 bug report at https://bugs.php.net/bug.php?id=72546&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72546&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72546&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72546&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72546&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72546&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72546&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72546&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72546&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72546&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72546&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72546&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72546&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72546&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72546&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72546&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72546&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72546&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72546&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72546&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72546&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#202064) next »