Skip to content

Stdlib: array_values()/array_merge() on enum case arrays coerces to backed scalars (ext/standard/array.c) #5547

Description

@PurHur

Category

stdlib

Problem

array_values() and array_merge() (and similar reindexing/copy builtins) must return arrays whose elements remain enum case objects. This compiler copies backing integers (backed enums) instead of enum(E::A) objects.

php-src reference

Repro

test/repro-maintainer/parity_array_values_merge_enum.php:

<?php
enum E: int { case A = 1; case B = 2; }
var_dump(array_values([E::B, E::A]));
var_dump(array_merge([E::A], [E::B]));
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_array_values_merge_enum.php
php bin/vm.php test/repro-maintainer/parity_array_values_merge_enum.php
'
Call Zend VM today
array_values([E::B,E::A]) array(0=>enum(E::B),1=>enum(E::A)) array(0=>int(2),1=>int(1))
array_merge([E::A],[E::B]) enum cases int(1), int(2)

Scope (this repo)

Layer Path
VM ext/standard/array_values.php, array_merge.php, lib/VM/EnumCaseSupport.php
JIT/AOT phase 2
Tests test/compliance/cases/stdlib/array_values_merge_enum.phpt

Done when

  • Repro var_dump matches Zend on VM
  • ./script/ci-fast.sh --filter array_values_merge_enum green

Related

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