Skip to content

PHP 8.5 unpack behavior change with "N" #19735

@thekid

Description

@thekid

Description

The following code:

<?php

var_dump(unpack(
  "cversion/c3flags/Ncreated/Nmodified/Nscale/Nduration",
  "\000\000\000\000\341,a\024\341,a\025\000\000\003\350\000\000\r\254"
));

Resulted in this output:

array(8) {
  ["version"]=>
  int(0)
  ["flags1"]=>
  int(0)
  ["flags2"]=>
  int(0)
  ["flags3"]=>
  int(0)
  ["created"]=>
  int(-517185260)
  ["modified"]=>
  int(-517185259)
  ["scale"]=>
  int(1000)
  ["duration"]=>
  int(3500)
}

But I expected this output instead:

array(8) {
  ["version"]=>
  int(0)
  ["flags1"]=>
  int(0)
  ["flags2"]=>
  int(0)
  ["flags3"]=>
  int(0)
  ["created"]=>
  int(3777782036)
  ["modified"]=>
  int(3777782037)
  ["scale"]=>
  int(1000)
  ["duration"]=>
  int(3500)
}

See https://3v4l.org/1rP6A

PHP Version

PHP 8.5.0-dev (cli) (built: Sep  4 2025 23:33:47) (NTS Visual C++ 2022 x86)
Copyright (c) The PHP Group
Zend Engine v4.5.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.0-dev, Copyright (c), by Zend Technologies

Operating System

Windows

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions