Req #70378 [NEW]: keyval (=effective value as array key) to complement strval/intval

From: Date: Fri, 28 Aug 2015 08:52:38 +0000
Subject: Req #70378 [NEW]: keyval (=effective value as array key) to complement strval/intval
Groups: php.standards 
Request: Send a blank email to standards-+get-847@lists.php.net to get a copy of this message
From: rn at alpha9marketing dot com Operating system: PHP version: Irrelevant Package: PHP Language Specification Bug Type: Feature/Change Request Bug description:keyval (=effective value as array key) to complement strval/intval Description: ------------ PHP offers strval, intval, floatval, doubleval to manually coerce values to desired types. This eases strict comparisons with the === operator within a desired type domain. One omission is that one can not trivially cast a value as it would be (internally) when that value is used as an array key. PHP apparently casts booleans to integers when they are used as array keys. A subset of numeric strings (minus hex / octal literal strings, potentially others) is cast to integers, as are floats (truncated towards zero). NULL is converted to an empty string. There is currently no built-in function that exposes this special type coersion used for array keys to the programmer, though one would have to assume it exists somewhere in the PHP code and exposing it would require only an external interface without (much) additional logic. Expected result: ---------------- php > var_dump(keyval(NULL)); string(0) "" php > var_dump(keyval(false)); int(0) php > var_dump(keyval(true)); int(1) php > var_dump(keyval(-1.734)); int(-1) php > var_dump(keyval(1.734)); int(1) php > var_dump(keyval("12")); int(12) php > var_dump(keyval("0xA")); string(3) "0xA" php > var_dump(keyval("017")); string(3) "017" -- Edit bug report at https://bugs.php.net/bug.php?id=70378&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70378&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70378&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70378&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70378&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70378&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70378&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70378&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70378&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70378&r=support Expected behavior: https://bugs.php.net/fix.php?id=70378&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70378&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70378&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70378&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70378&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70378&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70378&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70378&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70378&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70378&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70378&r=mysqlcfg

« previous php.standards (#847) next »