From: todd at magnifisites dot com Operating system: RH 9 PHP version: 4.3.6 PHP Bug Type: Strings related Bug description: strlen() integer not converted to string
Description: ------------ The substr() function will convert an integer and return the correct results. Using strlen() returns NULL, it does not convert an integer to string so that the expected results are returned. Reproduce code: --------------- $string = '12345'; $number = 12345; print substr($number, -1) . '<br />'; // works fine print $string{strlen($string)-1} . '<br />'; works fine // This won't work, $number is not a string: print $number{strlen($number)-1} . '<br />'; // Now cast it as a string and it will: $number = (string)$number; print $number{strlen($number)-1} . '<br />'; Expected result: ---------------- I would expect PHP to automagically convert the integer to a string without having to cast it as string first. -- Edit bug report at http://bugs.php.net/?id=28902&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28902&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28902&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=28902&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=28902&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=28902&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=28902&r=needscript Try newer version: http://bugs.php.net/fix.php?id=28902&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=28902&r=support Expected behavior: http://bugs.php.net/fix.php?id=28902&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=28902&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=28902&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=28902&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28902&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=28902&r=dst IIS Stability: http://bugs.php.net/fix.php?id=28902&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=28902&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=28902&r=float