Skip to content

Stdlib: version_compare() — shorter operand must compare like Zend (ext/standard/versioning.c) #4796

Description

@PurHur

Category

stdlib

Problem

version_compare() in ext/standard/VmInfo.php diverges from Zend when one operand has fewer dotted segments (e.g. 8.2 vs 8.2.31).

php-src reference

Repro

test/tmp/repro-version-compare-partial.php:

<?php
declare(strict_types=1);
var_export(version_compare('8.2.31', '8.2', '>='));
echo PHP_EOL;
./script/docker-exec.sh -- bash -lc 'php test/tmp/repro-version-compare-partial.php; php bin/vm.php test/tmp/repro-version-compare-partial.php'
Case Zend This compiler
version_compare('8.2.31', '8.2', '>=') true false

Scope

Module Path
VM ext/standard/VmInfo.php (phpVersionCompare / canonicalizeVersion)
JIT lib/JIT/Builtin/ / __compiler_version_compare if duplicated
Tests test/compliance/cases/stdlib/version_compare_partial.phpt

Done when

  • Repro matches Zend on VM (and JIT if lowered)
  • ./script/ci-fast.sh --filter version_compare_partial green

Related

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 3, 2026
  2. PurHur commented on Jun 3, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 3, 2026

    @PurHur
    OwnerAuthor

    Merged via #5327

    Root cause: canonicalizeVersion() treated . as a digit/non-digit boundary, producing 8..2..31 instead of 8.2.31.

    Fix: Match php-src versioning.c isdig/isndig — exclude . from the transition branch in VmInfo.php and phpc_info.c.

    Verification:

    php test/tmp/repro-version-compare-partial.php          → true
    php bin/vm.php test/tmp/repro-version-compare-partial.php → true
    vendor/bin/phpunit --filter version_compare_partial     → OK (2 tests)
    
  4. PurHur commented on Jul 30, 2026

    @PurHur
    OwnerAuthor

    Cleanup: deleting leftover test/tmp/ scratch repro for this closed issue — same coverage lives under test/compliance/cases/ (see PR chore/cleanup-stale-test-tmp-repros).

  5. PurHur commented on Jul 30, 2026

    @PurHur
    OwnerAuthor

    Cleanup follow-up: merged #25413 — test/tmp scratch repro removed.

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