#49636 [Opn]: PHP_INT_SIZE inconsistent with pack("i")
| From: | hsu at jean-david dot com | Date: | Thu, 24 Sep 2009 10:41:40 +0000 |
| Subject: | #49636 [Opn]: PHP_INT_SIZE inconsistent with pack("i") | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-142815@lists.php.net to get a copy of this message | ||
ID: 49636
User updated by: hsu at jean-david dot com
Reported By: hsu at jean-david dot com
Status: Open
Bug Type: Math related
Operating System: linux
PHP Version: 5.2.11
New Comment:
There is no easy way to pack a plain old php integer
This means that pack has many different format codes but none for a php
int?
Previous Comments:
------------------------------------------------------------------------
[2009-09-23 07:28:36] sjoerd@php.net
Thank you for your bug report.
The integer in the pack documentation and the integer in the PHP
integer documentation refer to different things. The pack integer is a
C-style int. The PHP integer is implemented in a long. These do not need
to be the same size.
------------------------------------------------------------------------
[2009-09-23 01:54:13] hsu at jean-david dot com
Description:
------------
PHP pack documentation:
i signed integer (machine dependent size and byte order)
PHP integer documentation:
Integer size can be determined using the constant PHP_INT_SIZE
On some systems, I believe that the word "integer" will refer to
objects of different sizes, such that pack("i", _) could point to an
object of size X bytes and PHP_INT_SIZE return value Y which is
inconsistent.
/main/main.c l.1796:
REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long),
CONST_PERSISTENT | CONST_CS);
/ext/standard/pack.c l.402-403:
php_pack(argv[currentarg++], sizeof(int), int_map,
&output[outputpos]);
outputpos += sizeof(int);
Reproduce code:
---------------
file_put_contents("test.bin",pack("I", 2));
var_dump(PHP_INT_SIZE === filesize("test.bin"));
Expected result:
----------------
bool(true)
Actual result:
--------------
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49636&edit=1