Skip to content

Stdlib: fdiv() — numeric-string coercion + TypeError parity (ext/standard/math.c) #4388

Description

@PurHur

Category

stdlib

Problem

fdiv() in ext/standard/fdiv.php only accepts int/float operands and throws LogicException for numeric strings and non-scalars. Zend PHP_FUNCTION(fdiv) uses Z_PARAM_DOUBLE: numeric strings coerce; arrays/objects throw TypeError.

php-src reference

Repro

Save as repro_fdiv.php:

<?php
var_dump(fdiv("6", "2"));
var_dump(fdiv("6.0", 2));
try {
    var_dump(fdiv([], 2));
} catch (Throwable $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n";
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_fdiv.php
php bin/vm.php repro_fdiv.php
'
Call Zend PHP 8.x This compiler (today)
fdiv("6","2") float(3) LogicException
fdiv("6.0", 2) float(3) LogicException
fdiv([], 2) TypeError LogicException

Scope (this repo)

Area Files
VM ext/standard/fdiv.phptoFloat() / operand validation
Shared ext/standard/VmMath.php — reuse double coercion helper (#4350)
JIT fdiv::call()unboxValueToDouble must not return 0.0 for invalid types silently
Tests test/compliance/cases/stdlib/fdiv_numeric_string.phpt

Done when

  • Numeric-string/bool/null operands coerce per Zend Z_PARAM_DOUBLE rules
  • Array/object/resource operands throw TypeError (not LogicException)
  • JIT/AOT match VM on repro (no silent 0.0 fallback for bad types)
  • ./script/ci-fast.sh --filter fdiv green
  • docs/capabilities.md matrix unchanged (already VM/JIT/AOT yes)

Links

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:compilerCompiler / CFG / JITarea:vmVirtual machineimplementation-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