|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27384 unpack() misbehaves with 1 char string
Submitted: 2004-02-24 15:17 UTC Modified: 2004-03-02 15:44 UTC
From: hayk at mail dot ru Assigned:
Status: Closed Package: Strings related
PHP Version: 4.3.4 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.
Block user comment
Status: Assign to:
Bug Type:
From: hayk at mail dot ru
New email:
PHP Version: OS:


 [2004-02-24 15:17 UTC] hayk at mail dot ru
When the function unpack returns an array with just one element, it doesn't have an index.

Reproduce code:
	$sp = chr(0x20);
	$a = unpack('C1', $sp);
<? print_r($a); ?>

Expected result:
    [] => 32

Actual result:
    [1] => 32


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-24 15:23 UTC] hayk at mail dot ru
I muddle up "Expected" and "Actual" results in the my submission.
 [2004-02-24 15:30 UTC]
You're not using unpack correctly.  The format string is


Name cannot begin with or be a number, as it would be 
impossible to distinguish multiplicty from name.
 [2004-02-24 15:42 UTC] hayk at mail dot ru
Why this code works fine?
	$sp = chr(0x20);
	$a = unpack('C2', $sp.$sp);
<? print_r($a); ?>
We get:
    [1] => 32
    [2] => 32
 [2004-02-24 16:42 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

I see what you're saying now.  This has been fixed in 
 [2004-02-25 07:29 UTC]
And fix was merged to the stable branch too..

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 01 02:01:29 2024 UTC