Skip to content

Stdlib: min()/max() — enum case operands must return enum objects not backing scalars (#5570 regression) #8729

Description

@PurHur

Category

stdlib · php-src-strict · regression

Problem

Zend min() / max() with backed enum case operands compares backing values and returns the winning enum case object. Closed #5570 / #5707 added VmMinMax::tryReduceEnumCasesTwoArg(), but VM still returns backing scalars (e.g. 1 instead of \E::A).

php-src reference

Repro

<?php
enum E: int { case A = 1; case B = 2; }
var_export(min(E::A, E::B));
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "enum E: int { case A=1; case B=2; } var_export(min(E::A,E::B)); echo \"\\n\";"
php bin/vm.php -r "enum E: int { case A=1; case B=2; } var_export(min(E::A,E::B)); echo \"\\n\";"'
Engine Output
Zend PHP 8.3+ \E::A
This compiler VM (today) 1

Also verify max(E::B, E::A) → \E::B, variadic min(E::A, E::B, …), and JIT/AOT when lowered.

Scope (this repo)

  • ext/standard/VmMinMax.php — tryReduceEnumCasesTwoArg(), finishEnumCaseReduce() must materialize enum case return zvals
  • lib/JIT/Builtin/*MinMax* — mirror enum return type
  • test/compliance/cases/stdlib/min_max_enum_case.phpt

Done when

  • Repro prints \E::A on VM (not 1)
  • max() symmetric
  • ./script/ci-fast.sh --filter min_max_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