FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Implied cast differs from explicit cast
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Implied cast differs from explicit cast [message #176657] Mon, 16 January 2012 01:10 Go to previous message
lb is currently offline  lb
Messages: 4
Registered: January 2012
Karma:
Junior Member
When converting some strings to int (or double), I am finding that
an implied cast get different results from explicit cast. This happens
when the string contains a hex representation. The implied cast converts
the hex value, but the explicit cast returns 0. The manual under "String
conversion to numbers" says nothing about it allowing hex values. This is
with PHP-5.3.9 and older.

Script:
<?php
$s1 = '0x12';
$t1 = $s1 + 0;
echo "Implied cast t1=$t1\n";
$t2 = (int)$s1 + 0;
echo "Explicit cast t2=$t2\n";

Output:
Implied cast t1=18
Explicit cast t2=0


I think this is odd. A side problem is that is_numeric('0x12') is true, but
((int)'0x12') is 0. Does anyone think this a bug?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Open Source Development
Next Topic: error from phpadmin
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 15:28:18 GMT 2024

Total time taken to generate the page: 0.04094 seconds