Skip to content

Stdlib: strnatcmp()/strcoll()/strncmp()/version_compare() — null/bool operands must TypeError (ext/standard/string.c) #10908

Description

@PurHur

Category

stdlib · php-src-strict

Problem

PHP 8+ string-typed compare builtins must TypeError when operands are null, bool, or other non-string scalars — not silently coerce (e.g. strnatcmp(null,'1')-1). This compiler returns comparison integers instead of failing.

Related but narrower: #4346 (array/object operands on strcmp family), #8825 (enum case operands).

php-src reference

Repro (failure today)

test/repro/maintainer_gap_string_compare_null_scalar.php:

php test/repro/maintainer_gap_string_compare_null_scalar.php      # all TypeError
php bin/vm.php test/repro/maintainer_gap_string_compare_null_scalar.php  # uncaught / returns int
Call Zend VM today
strnatcmp(null,'1') TypeError returns -1
strcoll(null,'a') TypeError returns -97
strncmp(null,'a',1) TypeError returns 0
version_compare(null,'1.0') TypeError returns -1
strcmp(true,'1') TypeError returns 0

Scope (this repo)

Path Work
ext/standard/ compare builtins Reuse VmString::coerceStringBuiltinArg / shared string-arg guards
lib/JIT/ Same TypeError shapes when lowered

PHP-in-PHP: guards in PHP builtins; shrink any C-only coercion.

Done when

  • Repro prints TypeError for every case on VM
  • Valid string operands still compare like Zend
  • JIT/AOT agree if these calls are JIT-lowed

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 appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions