Skip to content

Stdlib: version_compare() — invalid $operator must throw ValueError (ext/standard/versioning.c parity) #4319

Closed

Description

@PurHur

Summary

When the third argument to version_compare() is not a valid comparison operator, Zend throws ValueError. This compiler returns normally (no exception) — silent wrong behavior.

php-src reference

Repro

test/repro-maintainer/version_compare_invalid_operator.php

HARNESS_DOCKER_RUN_OPTS='--memory=8g --cpus=2' ./script/docker-exec.sh -- bash -lc '
  source script/php-env.sh
  php test/repro-maintainer/version_compare_invalid_operator.php
  php bin/vm.php test/repro-maintainer/version_compare_invalid_operator.php
'
Mode version_compare('1','2','??')
Zend ValueError: … must be a valid comparison operator
VM prints no_ex (no exception)

Implementation notes

  • ext/standard/VmInfo.php — applyVersionCompareOperator() throws LogicException today; switch to ValueError with Zend message and ensure all invalid operators are rejected (including silent fall-through).
  • JIT/AOT: JitInfo::version_compare / runtime __compiler_version_compare if operator is lowered.

Verification

  • Extend test/compliance/cases/stdlib/version_compare.phpt or add dedicated PHPT

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 2, 2026
  2. PurHur commented on Jun 9, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 9, 2026

    @PurHur
    OwnerAuthor

    Merged via #7840.

    Fix: Invalid version_compare() $operator now throws ValueError on VM, JIT, and AOT compile paths (php-src ext/standard/versioning.c parity).

    Verification:

    • Repro: php bin/vm.php / php bin/jit.php test/repro-maintainer/version_compare_invalid_operator.php → ValueError message
    • Compliance: vendor/bin/phpunit --filter version_compare_invalid_operator → VM + JIT green
    • AOT lint: php bin/compile.php -l test/repro-maintainer/version_compare_invalid_operator.php → exit 0

    Also fixed StringVersionCompareJit::emitCompareSpecialForms() branchIf typo that blocked AOT LLVM lowering for valid-operator calls.

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