php.net |  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:
 [2004-02-24 15:17 UTC] hayk at mail dot ru
Description:
------------
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);
?>
<pre>
<? print_r($a); ?>
</pre>

Expected result:
----------------
Array
(
    [] => 32
)

Actual result:
--------------
Array
(
    [1] => 32
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] gschlossnagle@php.net
You're not using unpack correctly.  The format string is

Type.Multiplicity.Name

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);
?>
<pre>
<? print_r($a); ?>
</pre>
We get:
Array
(
    [1] => 32
    [2] => 32
)
 [2004-02-24 16:42 UTC] gschlossnagle@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

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

 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 10:02:06 2014 UTC