ID:               28902
 Updated by:       [EMAIL PROTECTED]
 Reported By:      todd at magnifisites dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Strings related
 Operating System: All
 PHP Version:      4.3.8-dev
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is intended behavior. 


Previous Comments:
------------------------------------------------------------------------

[2004-06-24 01:51:32] [EMAIL PROTECTED]

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.

------------------------------------------------------------------------

[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

Reply via email to