php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46534 Incorrect usage of SI-prefixes by PHP
Submitted: 2008-11-10 11:12 UTC Modified: 2011-04-08 18:07 UTC
Votes:16
Avg. Score:4.5 ± 1.1
Reproduced:12 of 14 (85.7%)
Same Version:3 (25.0%)
Same OS:6 (50.0%)
From: alexanderpas at yahoo dot co dot uk Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alexanderpas at yahoo dot co dot uk
New email:
PHP Version: OS:

 

 [2008-11-10 11:12 UTC] alexanderpas at yahoo dot co dot uk
Description:
------------
PHP is handling kilo and other SI prefixes as multiples of 1024.

The SI prefixes should only be used in the decimal sense: kilobyte and megabyte denote one thousand bytes and one million bytes respectively, while kibibyte and mebibyte denote 1024 bytes and 1,048,576 bytes respectively. This recommendation has been adopted by SI, IEEE, CIPM, NIST, ISO/IEC and some other leading national and international standards, which now state that the prefixes k, M and G should always refer to powers of ten, even in the context of information technology. (reference: ISO/IEC IEC 80000-13:2008 )

reduced timeline:
1998:
IEC introduces unambigous prefixes for binary multiples (KiB, MiB, GiB etc.), reserving kB, MB, GB and so on for their decimal sense.

2005:
IEC prefixes are adopted by the IEEE after a two-year trial period.

2008:
NIST guidelines require use of IEC prefixes KiB, MiB ... (and not kB, MB) for binary byte multiples

“The names and symbols for the prefixes corresponding to 2 10 , 2 20 , 2 30 , 2 40 , 2 50 , and 2 60 are, respectively: kibi, Ki; mebi, Mi; gibi, Gi; tebi, Ti; pebi, Pi; and exbi, Ei. Thus, for example, one kibibyte would be written: 1 KiB = 2 10 B = 1024 B, where B denotes a byte. Although these prefixes are not part of the SI, they should be used in the field of information technology to avoid the incorrect usage of the SI prefixes.”

also remember this:
decimal value 	binary value 	difference 	
10001 = 103 	10241 = 210 	2.4%
10002 = 106 	10242 = 220 	4.9%
10003 = 109 	10243 = 230 	7.4%
10004 = 1012 	10244 = 240 	10.0%
10005 = 1015 	10245 = 250 	12.6%
10006 = 1018 	10246 = 260 	15.3%
10007 = 1021 	10247 = 270 	18.1%
10008 = 1024 	10248 = 280 	20.9%

also, this has a usability impact, since using the same wording with two different meanings is JUST PLAIN WRONG, and should end RIGHT NOW, Regular users don't know that the units have dual meanings, and we shouldn't continue confusing them in this way.

also "man 7 units" on your linux-box ;)

(please put in correct category!)

Reproduce code:
---------------
<?php
ini_set('memory_limit', '32M');
for ($i=0; $i<=100000000; $i++) {
        $var.="a";
}

Expected result:
----------------
Fatal error: Allowed memory size of 32000000 bytes exhausted (tried to allocate more bytes) in ./testcase.php on line 4

Actual result:
--------------
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 33292265 bytes) in ./testcase.php on line 4

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-10 14:00 UTC] alexanderpas at yahoo dot co dot uk
proper table...
decimal value 	binary value 	difference 	
1000^1 = 10^3 	1024^1 = 2^10 	2.4%
1000^2 = 10^6 	1024^2 = 2^20 	4.9%
1000^3 = 10^9 	1024^3 = 2^30 	7.4%
1000^4 = 10^12 	1024^4 = 2^40 	10.0%
1000^5 = 10^15 	1024^5 = 2^50 	12.6%
1000^6 = 10^18 	1024^6 = 2^60 	15.3%
1000^7 = 10^21 	1024^7 = 2^70 	18.1%
1000^8 = 10^24 	1024^8 = 2^80 	20.9%
 [2009-04-24 00:47 UTC] kriceslo at gmail dot com
This needs to be addressed. We, in the IT field, need to start using the correct units--now standardized and accepted BY LAW in some countries.

Great job alexanderpas!
 [2009-09-03 16:07 UTC] alexanderpas at yahoo dot co dot uk
Note that even Mac OS X v10.6 is using 1000 bytes per kilobyte. (http://support.apple.com/kb/TS2419)

Linux is using it for years already (units(8) manual page)

The only operating system still using 1024 for kilo is Microsoft Windows

I suggest we use the proper and full kilobyte and kibibyte definitions as soon as possible!
 [2009-09-03 16:09 UTC] alexanderpas at yahoo dot co dot uk
units(7) manual page ofcourse
 [2011-04-08 18:07 UTC] jani@php.net
-Package: Feature/Change Request +Package: Scripting Engine problem
 [2011-04-08 18:07 UTC] jani@php.net
-PHP Version: 6 +PHP Version: *
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Thu Jul 19 04:01:24 2018 UTC