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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
14 + 37 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 19:01:29 2024 UTC