理解PHP的intval函数,案例:康盛UCenter Home (UCH)
int intval ( mixed $var [, int $base= 10 ] ) |
这个方法很简单,文档请参阅http://cn2.php.net/intval
这里想强调的一下:
- 整数在32位系统上的最大值是2^31 – 1 ,如果超过,就会溢出
- 传给intval的参数如果是字符串类型,且字符串表示的数字超过了最大值,就只会保留最大值
即:
echo intval(2147483648); // -2147483648 echo intval("2147483648"); // 2147483647 |
练习题:
康盛公司出品的山寨社会化网络(SNS)软件UCenter Home ,即UCH ,有一个相册功能,其代码( source/function_cp.php )中包含一句:
$maxattachsize = intval(checkperm('maxattachsize'));//单位MB |
其用途是获取用户的可用空间。里面注释是UCHOME自带的,而且是错误的。实际上checkperm返回的单位是字节,而且是整数类型的字节。引起的直接bug是,如果给用户分配的可用空间超过2G,就会溢出,在这里检查可用空间就变成负数了。
请尝试修改上述代码。
原创文章如转载,请注明:转载自CODIGG [ http://www.codigg.com/ ]
本文链接地址:http://www.codigg.com/2009/05/php-intval-uchome/


一月 31st, 2012 at 04:26
I was more than happy in finding this blog! ! ! I really wished to give thanks to you for your time, energy intended for this excellent article. . ! I certainly taking advantage of pretty much every little piece of it and, I have this document saved to fav to check out brand-new issues you write.
[回复]
一月 31st, 2012 at 09:46
Also there are a certain amount of useful tips in time throughout this specific guide however I personally don’t understand if I simply find just about all of these center to heart. Presently there is some validity however I really can take hold viewpoint till I have a look in to that further. High-quality write-up , Thanks! ! and I truly like much more! Added to bookmarks as well
[回复]
二月 3rd, 2012 at 02:12
Gday vso software convertxtodvd crack magnificent write-up vso software convertxtodvd license key for ç†è§£PHPçš„intval函数,案例:康盛UCenter Home (UCH) – CODIGG
[回复]
二月 3rd, 2012 at 10:45
I imagine this is some form of evolutionary trait to determine what type of person someone is. Whether they are out to get vengence, if they are different, someone that you need to be cautious about. Most people would would need this knowledge how to deal to them.
[回复]
二月 4th, 2012 at 13:06
I used to be curious about your following submit admin seriously required this weblog super remarkable web site
[回复]
二月 5th, 2012 at 08:25
Great 1 website owner good results blog publish good sharings within this blog often have pleasurable
[回复]