ID: 28902 Updated by: [EMAIL PROTECTED] -Summary: strlen() integer not converted to string Reported By: todd at magnifisites dot com Status: Open Bug Type: Strings related -Operating System: RH 9 +Operating System: All -PHP Version: 4.3.6 +PHP Version: 4.3.8-dev New Comment:
It's not strlen() that's failing. It's the $number{$offset} syntax. I can see the argument for casting $number to a string when string offset syntax is used, but I'm not sure enough it's the right thing to do. Previous Comments: ------------------------------------------------------------------------ [2004-06-23 23:23:40] todd at magnifisites dot com 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 this bug report at http://bugs.php.net/?id=28902&edit=1