Skip to content

Stdlib: unpack() — enum case operands must warn+pack backing int like Zend (ext/standard/pack.c, php-src-strict) #6213

Description

@PurHur

Category

stdlib

Problem

unpack() (and enum operands passed into pack() for the data buffer) do not match Zend when a backed enum case is used where an int/string scalar is expected. Zend emits a Warning: Object of class E could not be converted to int and proceeds using the backing value. This compiler fatals via VmJson::export / unsupported value type (verified 2026-06-05).

Related: #5713 tracks pack() enum behavior; this issue covers unpack() and the full pack/unpack pipeline.

php-src reference

Repro (verified 2026-06-05)

<?php
enum E: int { case A = 1; }
$data = pack('c', E::A);
var_dump(unpack('c', $data));
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php
php bin/vm.php repro.php
'
Step Zend PHP 8.2 bin/vm.php (today)
pack('c', E::A) Warning + packs byte 0x01 Warning path differs; may fatal ❌
unpack('c', $data) array(1 => int(1)) VM fatal: json_encode() value type not supported

Direct enum into unpack format args should also TypeError per Z_PARAM_STR on format string — test separately.

Scope (PHP-in-PHP)

Path Change
ext/standard/unpack.php, ext/standard/pack.php scalar coercion via VmPack / UnpackEngine — enum case → backing with Zend warning
ext/standard/VmPack.php, UnpackEngine.php never route enum cases through VmJson::export
lib/JIT/Builtin/JitUnpack.php, JitPack.php mirror coercion when JIT lowered
Tests test/compliance/cases/stdlib/unpack_enum_case.phpt, extend pack_enum_case.phpt

Done when

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter unpack_enum'
./script/ci-fast.sh --filter UnpackEnum

Links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions