Skip to content

Fix unpack() offset error naming a nonexistent parameter - #24215

Merged
LamentXU123 merged 1 commit into
php:masterfrom
lacatoire:fix/unpack-offset-parameter-name
Oct 9, 2026
Merged

LamentXU123 merged 1 commit into
php:masterfrom
lacatoire:fix/unpack-offset-parameter-name

Conversation

@lacatoire

Copy link
Copy Markdown
Member

The unpack() error for an out-of-range $offset names a parameter that does not exist. The signature is unpack(string $format, string $string, int $offset = 0), and $data was renamed to $string in 25f1c40.

try { unpack("N", "abcd", 9); } catch (ValueError $e) { echo $e->getMessage(); }

Before:

unpack(): Argument #3 ($offset) must be contained in argument #2 ($data)

After:

unpack(): Argument #3 ($offset) must be contained in argument #2 ($string)

unpack_offset.phpt is updated, and now also lists the parameter names through Reflection so a future rename cannot leave this message stale. The test passes.

The message cross-references argument #2 as $data, a name unpack() lost
in 25f1c40 when the ext/standard parameters were renamed for 8.0; it
is $string. The same phrasing elsewhere, in substr_count() and friends,
names the real parameter.
@LamentXU123
LamentXU123 merged commit a276f5d into php:master Oct 9, 2026
17 of 18 checks passed
@lacatoire
lacatoire deleted the fix/unpack-offset-parameter-name branch October 9, 2026 14:23
arnaud-lb added a commit to frodeborli/php-src that referenced this pull request Oct 9, 2026
* up/master: (180 commits)
  Changed the test expected result of `pdo_mysql/bug76815_pdo_mysql_f to %d (php#13808)
  ext/standard: name the real parameter in the unpack() offset error (php#24215)
  ext/readline: Refactor CLI readline completion generators
  Fix phpGH-24081: User opcode DISPATCH runs on a stale frame in the TAILCALL VM
  ext/standard: Validate the bcrypt cost before reading it
  JIT: Avoid object type check if the object is known to be a type (php#24086)
  zend_alloc: move a small block shrunk to the size of the bin below
  Fix phpGH-23979: Nullsafe operator must not flush delayed oplines of an enclosing function
  ext/zip: Reject ZipArchive mutators during close() (php#24025)
  Fix OSS-Fuzz #568005340: FETCH_DIM_FUNC_ARG partial conversion
  Fix too wide type inference for ASSIGN_DIM_OP
  Fix type inference of ADD_ARRAY_UNPACK with integer keys
  Evaluate ZEND_SPACESHIP in SCCP
  Add range inference for SPACESHIP
  JIT: Optimize array checks in comparisons (php#24084)
  Fix leak when the added previous exception is already in the chain (php#24177)
  date: Add `php_date_time_duration_create()` in a new `time_duration.h` (php#24072)
  ext/zip: Fix use-after-free in the archive destructor path (php#23779)
  ext/standard: Optimize array_chunk() by filling packed chunks directly
  Fix phpGH-17626: JIT corrupts opline handler when blacklisting root trace
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants