Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #4468
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Implied cast differs from explicit cast |
| Date | 2012-01-15 20:51 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <jevvqe$1gk$1@dont-email.me> (permalink) |
| References | <4f1378ee$0$16741$882e7ee2@usenet-news.net> |
On 1/15/2012 8:10 PM, lb wrote:
> 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?
>
>
No, it is not. '0x12' is a hex number, not an integer. (int)'0x12'
converts this correctly to 0.
If you want to convert a hex number to an integer, you need to use
hexdec(), which is what the implied conversion does.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Implied cast differs from explicit cast lb <lb2048@pobox.com.delete> - 2012-01-16 01:10 +0000
Re: Implied cast differs from explicit cast Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-15 20:51 -0500
Re: Implied cast differs from explicit cast lb <lb2048@pobox.com.delete> - 2012-01-16 03:08 +0000
Re: Implied cast differs from explicit cast Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-15 22:39 -0500
Re: Implied cast differs from explicit cast Arno Welzel <usenet@arnowelzel.de> - 2012-01-16 08:42 +0100
Re: Implied cast differs from explicit cast Curtis Dyer <dyer85@gmail.com> - 2012-01-16 09:04 +0000
Re: Implied cast differs from explicit cast Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-16 08:25 -0500
Re: Implied cast differs from explicit cast "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-16 19:51 +0100
Re: Implied cast differs from explicit cast The Natural Philosopher <tnp@invalid.invalid> - 2012-01-16 13:28 +0000
Re: Implied cast differs from explicit cast Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-16 08:45 -0500
Re: Implied cast differs from explicit cast Arno Welzel <usenet@arnowelzel.de> - 2012-01-17 06:59 +0100
Re: Implied cast differs from explicit cast Arno Welzel <usenet@arnowelzel.de> - 2012-01-17 07:00 +0100
Re: Implied cast differs from explicit cast Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-17 08:17 -0500
Re: Implied cast differs from explicit cast Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-17 08:16 -0500
Re: Implied cast differs from explicit cast Arno Welzel <usenet@arnowelzel.de> - 2012-01-19 13:36 +0100
Re: Implied cast differs from explicit cast Arno Welzel <usenet@arnowelzel.de> - 2012-01-19 13:39 +0100
Re: Implied cast differs from explicit cast Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-19 09:06 -0500
Re: Implied cast differs from explicit cast Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-19 09:05 -0500
Re: Implied cast differs from explicit cast The Natural Philosopher <tnp@invalid.invalid> - 2012-01-19 15:01 +0000
Re: Implied cast differs from explicit cast Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-19 14:41 -0500
Re: Implied cast differs from explicit cast "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-16 09:49 +0100
Re: Implied cast differs from explicit cast "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2012-01-16 11:48 +0100
Re: Implied cast differs from explicit cast lb <lb2048@pobox.com.delete> - 2012-01-17 02:35 +0000
csiph-web