You are here: Re: [PHP] Declaring vars as INT ? « PHP « IT news, forums, messages
Re: [PHP] Declaring vars as INT ?

Posted by "Richard Lynch" on 10/23/05 05:53

On Fri, October 21, 2005 2:39 pm, Chris Knipe wrote:
> Function DoSomething($Blah) {
> $Blah = (int) $Blah;
> return $Blah
> }
>
> $Blah, cannot be larger than 2147483647, and sometimes, I get negative
> integers back from the above function.
>
> This is with PHP 4.4.0 on FreeBSD 5.4-STABLE. Can anyone else perhaps
> confirm this, and if it is indeed true, is this a bug, or a limitation
> somewhere on PHP? Any other ways to confirm that *large* numbers, are
> indeed integers? I'm working with numbers in the form of yyyymmddsss
> (20051025001 for today for example)

PHP integers are limited by 32-bit hardware and a simplicity of design
to -2147483648 to 2147483647.

There are no unsigned, long, double long, or google ungle longles.
[I made that last one up, but it sure sounds good, don't it?]

Your options are, however, several.

1. Use BCMATH or that fancy new-fangled big-number package to deal
with numbers as big as you want, subject only to the amount of RAM in
your box and the number of values you want to use at one time.
Performance will not be integer-fast as these packages use
string-manipulation to compute mathematical values, but they can get
VERY big numbers, with whatever precision you specify.

2. In this particular instance, it's a *DATE* so you should consider
converting it to a Unix time-stamp. This does limit you to 1/1/1970
midnight to somewhere in March 2038, however, as that is the same
32-bit limited range in number of seconds between 1/1/1970 midnight
and 2 * 2147483647 seconds later than that. Note that this is
strictly hardware-based, so if you get a 64-bit machine, your date
range goes until, like, 1970 + 2 * (2038 - 1970)

If your dates range beyond 1/1/1970 and/or 2038, you may want to
simply NOT convert them to integer in the first place.

Also note that database software can generally provide more options
for date storage, date arithmetic and date-handling in general.

--
Like Music?
http://l-i-e.com/artists.htm

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация