|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72315 Unpack 'J' & 'P' doesn't produce expected results
Submitted: 2016-06-02 10:56 UTC Modified: 2016-06-02 11:20 UTC
From: ads at tristanleboss dot net Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 7.0.7 OS: Windows 7 x64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: ads at tristanleboss dot net
New email:
PHP Version: OS:


 [2016-06-02 10:56 UTC] ads at tristanleboss dot net

While doing some tests, I discovered the 'P' format (unsigned long long (always 64 bit, little endian byte order)) and the 'J' format (unsigned long long (always 64 bit, big endian byte order)) are not giving the expected results on my Windows 7 x64 test machine with PHP 7.0.7RC1.

Indeed, they don't account for the "unsigned" nature and output the signed version.


unpack('P', "\xC0\x00\xF8\x90\x32\x04\x00\x90") will output "-8070445917020880704".

The expected result is "13835331353480265872".

unpack('J', "\xC0\x00\xF8\x90\x32\x04\x00\x90") will output "-4611412720229285744".

The expected result is "10376298156688670912".

No error/warning message will be displayed.

Test script:

var_dump( unpack('P', "\xC0\x00\xF8\x90\x32\x04\x00\x90") );

var_dump( unpack('J', "\xC0\x00\xF8\x90\x32\x04\x00\x90") );

Expected result:
array(1) {
array(1) {

Actual result:
array(1) {
array(1) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-02 10:57 UTC] ads at tristanleboss dot net
-Package: *Mail Related +Package: *Math Functions
 [2016-06-02 10:57 UTC] ads at tristanleboss dot net
Package: Math functions
 [2016-06-02 11:20 UTC]
-Status: Open +Status: Not a bug
 [2016-06-02 11:20 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

There's a yellow Caution note on the docs page that says PHP uses signed ints, so if you unpack() a large enough number you'll get one signed even if you asked for unsigned. And your two numbers (10e18 and 13e18) are beyond the limit of a signed integer (PHP_INT_MAX=9e18).
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 07:01:28 2024 UTC