Skip to content

Stdlib: strlen() scalar operands — TypeError not Zend string coercion (ext/standard/string.c) #11263

Closed

Description

@PurHur

Category

stdlib

Problem

Zend strlen() accepts bool/int/float/null operands by coercing them to strings (strlen(false) → 0, strlen(null) → 0, strlen(1.5) → 3, etc.). This compiler’s VM raises TypeError for all non-string scalars, breaking php-src-strict parity for legacy code.

Distinct from #10775 (inline array literal LogicException) and strict-types user code paths.

php-src reference

Repro

<?php
foreach ([false, true, 0, 1, 1.5, null] as $v) {
    try {
        echo gettype($v), '=', strlen($v), ' ';
    } catch (Throwable $e) {
        echo gettype($v), '=', get_class($e), ' ';
    }
}
echo "\n";

Committed: test/repro/maintainer_gap_strlen_scalar_coerce.php

./script/docker-exec.sh -- bash -lc '
  source script/php-env.sh
  php test/repro/maintainer_gap_strlen_scalar_coerce.php
  php bin/vm.php test/repro/maintainer_gap_strlen_scalar_coerce.php
'
Operand Zend PHP 8.2 This compiler VM
false 0 TypeError
true 1 TypeError
0 / 1 1 TypeError
1.5 3 TypeError
null 0 TypeError

Scope (PHP-in-PHP)

Layer Path
VM ext/standard/strlen.php, VmString::coerceStringBuiltinArg (shared with other string builtins)
JIT/AOT lib/JIT/Builtin/String* handlers
Tests compliance PHPT; align with #11261 strcmp null coercion guards

Done when (php-src-strict)

  • Scalar coercion matches Zend for repro operands; array/object still TypeError.
  • VM/JIT/AOT agree; reuse shared coercion helper (no per-builtin one-offs).

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

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — batch (issues #11260, #11261, #11263)

  3. PurHur commented on Jun 24, 2026

    @PurHur
    OwnerAuthor

    Merged #11269 — VM scalar coercion + enum guard unchanged; AOT compile.php -l green on repro.

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