#39901 [NEW]: casting of string with numbers in it still does INT conversion

From: Date: Wed, 20 Dec 2006 13:16:42 +0000
Subject: #39901 [NEW]: casting of string with numbers in it still does INT conversion
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-106636@lists.php.net to get a copy of this message
From: schizoduckie at gmail dot com Operating system: Win32/XP PHP version: 5CVS-2006-12-20 (snap) PHP Bug Type: Variables related Bug description: casting of string with numbers in it still does INT conversion Description: ------------ In a switch, a value that is declared as string with a prefix 0 will automatically disappear in switched values, even if all of them are specifically casted as a string. Reproduce code: --------------- $field = (string)"0123"; settype($field, 'string'); // just to make sure, for testcase switch ($field) { case '123': $result = 'first'; break; case '456': $result = 'second'; break; default: $result = 'third'; break; } echo $result; // first, due to string / int conversion. switch ((string)$field) // explicit cast to string { case (string)'123': $result = 'first'; break; // more (unneccesary casts just to be sure) case (string)'456': $result = 'second'; break; default: $result = 'third'; break; } echo $result; // first! ???? Expected result: ---------------- I would have expected the last result echo to be third because of the explicit typecasting. This problem appears in all php versions up to 5.2 snapshot of today. Actual result: -------------- the code in the example speaks for itself. -- Edit bug report at http://bugs.php.net/?id=39901&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39901&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39901&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39901&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39901&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39901&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39901&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39901&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39901&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39901&r=support Expected behavior: http://bugs.php.net/fix.php?id=39901&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39901&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39901&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39901&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39901&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39901&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39901&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39901&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39901&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39901&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39901&r=mysqlcfg

« previous php.bugs (#106636) next »