From:             thuejk at gmail dot com
Operating system: All
PHP version:      5.2.0
PHP Bug Type:     Feature/Change Request
Bug description:  Auto trunkation of floats to ints in array indices should 
raise a warning

Description:
------------
As described in
http://php.net/manual/en/language.types.array.php
"Floats in key are truncated to integer."

This is somewhat unintuitive, and caught me the first time I met it. A PHP
bug search shows me that other people were surprised too.

So to be kind to the programmers, also the ones who doesn't know the
manual by heart, I would like to suggest that an E_STRICT error or similar
be raised when the truncation is done.

Reproduce code:
---------------
error_reporting(E_ALL | E_STRICT);

$x = 1.6;
$y = 1.7;
$a = Array();

$a[$x] = 1;
$a[$y] = 2;

echo $a[$x];


Expected result:
----------------
It prints out "2" in accordance with the manual

An E_STRICT is raised, as you are trying to use floats in a place where
they do not belong. The E_STRICT error should recommend an explicit cast
to int in the code.

Actual result:
--------------
It prints out "2" in accordance with the manual

No E_STRICT error is raised.

-- 
Edit bug report at http://bugs.php.net/?id=39916&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39916&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39916&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39916&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39916&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39916&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39916&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39916&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39916&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39916&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39916&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39916&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39916&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39916&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39916&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39916&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39916&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39916&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39916&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39916&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39916&r=mysqlcfg

Reply via email to