#49636 [Fbk-Csd]: PHP_INT_SIZE inconsistent with pack(i)

2009-10-02 Thread hsu at jean-david dot com
 ID:   49636
 User updated by:  hsu at jean-david dot com
 Reported By:  hsu at jean-david dot com
-Status:   Feedback
+Status:   Closed
 Bug Type: Strings related
 Operating System: linux
 PHP Version:  5.2.11
 New Comment:

If there were a pack format character which is exactly the size of a
PHP int, this would mean only PHP with the same int size could read it
This is also true with the i format.

The reason that I use pack is to manipulate bit streams in PHP, but
yes, I would use serialize to just store an int.
You are right, there is no big inconvenience using the l format and 
it's fixed size.

I did not know that it was a design choice not to have a format
character for a PHP int.
Yes, please mark this bug as solved.
Thank you for the explanation.


Previous Comments:


[2009-10-01 11:35:57] sjo...@php.net

Correct. You can assume that an PHP int is always 32 bits and use l for
pack. However, pack() is probably the wrong tool for the thing you want
to do.

The pack() function is mainly useful to interoperate with other
programs or protocols. In that case, you typically know the format and
sizes of things you want to pack.

If there were a pack format character which is exactly the size of a
PHP int, this would mean only PHP with the same int size could read it.
If you want to store and retrieve data using only PHP, you are better
off using serialize().

Is this clear, and do you consider this bug solved?



[2009-09-24 10:41:35] hsu at jean-david dot com

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?



[2009-09-23 07:28:36] sjo...@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=49636edit=1



#49636 [Opn]: PHP_INT_SIZE inconsistent with pack(i)

2009-09-24 Thread hsu at jean-david dot com
 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] sjo...@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=49636edit=1



#49636 [NEW]: PHP_INT_SIZE inconsistent with pack(i

2009-09-22 Thread hsu at jean-david dot com
From: hsu at jean-david dot com
Operating system: linux
PHP version:  5.2.11
PHP Bug Type: Variables related
Bug description:  PHP_INT_SIZE inconsistent with pack(i

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 bug report at http://bugs.php.net/?id=49636edit=1
-- 
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=49636r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=49636r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=49636r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=49636r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49636r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=49636r=alreadyfixed
Need backtrace:  
http://bugs.php.net/fix.php?id=49636r=needtrace
Need Reproduce Script:   
http://bugs.php.net/fix.php?id=49636r=needscript
Try newer version:   
http://bugs.php.net/fix.php?id=49636r=oldversion
Not developer issue: 
http://bugs.php.net/fix.php?id=49636r=support
Expected behavior:   
http://bugs.php.net/fix.php?id=49636r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=49636r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=49636r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=49636r=globals
PHP 4 support discontinued:  http://bugs.php.net/fix.php?id=49636r=php4
Daylight Savings:http://bugs.php.net/fix.php?id=49636r=dst
IIS Stability:   
http://bugs.php.net/fix.php?id=49636r=isapi
Install GNU Sed: 
http://bugs.php.net/fix.php?id=49636r=gnused
Floating point limitations:  
http://bugs.php.net/fix.php?id=49636r=float
No Zend Extensions:  
http://bugs.php.net/fix.php?id=49636r=nozend
MySQL Configuration Error:   
http://bugs.php.net/fix.php?id=49636r=mysqlcfg