23
2011
PHP strtotime in 64 bit environment
The strtotime function is used to convert a date in various formats to a timestamp. However its behaviour is different based on architecture it is running on, whether 32bit or 64bit.
Lets take a few examples :
In 64 bit environment
desktop:~$ php -a
Interactive shell
php > echo strtotime("0000-00-00 00:00:00");
-62170005200
php > echo strtotime('1000-01-30');
-30607739600
php > echo strtotime('2100-01-30');
4104930600
php >
Over here we can see that strtotime is producing timestamps for far dates like 30-01-2100 and 30-01-1000 and even 00-00-0000
whereas on a 32 bit machine it would do this :
echo var_dump(strtotime("0000-00-00 00:00:00"));
echo var_dump(strtotime('1000-01-30'));
echo var_dump(strtotime('2100-01-30'));
Output :
bool(false) bool(false) bool(false)
So strtotime is not able to handle far away dates on a 32bit machine.
This can have effects in your code. For example if you are checking a date to be valid based on whether strtotime returns false or not :
if(! strtotime($date))
{
//error
}
Then the above approach would fail when the machine is 64 bit, because strtotime would simply succeed. On 64 bit , the date range for strtotime is quite large compared to that on 32 bit. Therefore an indepth checking of date range is necessary on the more powerful 64bit architecture.
Popularity: 1% [?]
Related Posts
Subscribe
Recent Posts
- Login into phpmyadmin without username and password
- 10+ tips to localise your php application
- 40+ Techniques to enhance your php code – Part 3
- 40+ Techniques to enhance your php code – Part 2
- 40+ Techniques to enhance your php code – Part 1
- CSSDeck – Collection of Pure CSS Creations
- Execute shell commands in PHP
- Php get list of locales installed on system
- Sound cracking in Ubuntu 11.10
- PHP script to perform IP whois
An article by





[...] 它们將是bool(false). 查看这里, [...]
[...] 它们將是bool(false). 查看这里, [...]
[...] 它们將是bool(false). 查看这里, [...]
[...] 它们將是bool(false). 查看这里, [...]
[...] ????bool(false). ????, [...]
[...] ????bool(false). ????, [...]