php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61169 unpack() with unnamed elements
Submitted: 2012-02-23 13:24 UTC Modified: 2016-09-26 17:01 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: anon at anon dot anon Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2012-02-23 13:24 UTC] anon at anon dot anon
Description:
------------
---
From manual page: http://www.php.net/function.unpack#refsect1-function.unpack-notes
---

A paragraph in the documentation for unpack says:

>Be aware that if you do not name an element, an empty string is used. If you do not name more than one element, this means that some data is overwritten as the keys are the same such as in: 

It is not correct that an empty string is used. The index 1 is used.

var_dump(unpack('V', 'abcd'));

array(1) {
  [1]=>
  int(1684234849)
}

(It could not be inferred that the documentation means an empty string with "1" appended, because the number is not appended to a lone entry's name:)

var_dump(unpack('Vname', 'abcd'));

array(1) {
  ["name"]=>
  int(1684234849)
}

Here's a clearer way to write it:

>If you do not name an element, numeric indices starting from 1 are used. Be aware that if you have more than one unnamed element, some data is overwritten because the numbering restarts from 1 for each element.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-26 17:00 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=340197
Log: Fix #61169: unpack() with unnamed elements
 [2016-09-26 17:01 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=fa71ef64bc552e4cb5d81ef5eb1cedb4bfeb141c
Log: Fix #61169: unpack() with unnamed elements
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 05 06:01:36 2025 UTC