Skip to content

Stdlib: number_format() — TypeError when $num is not int/float (ext/standard/number_format.c parity) #4163

Description

@PurHur

Category

stdlib

Problem

number_format() argument #1 must be int|float in PHP 8+. Passing an array must throw TypeError. This compiler fails to validate and may proceed with undefined behavior instead of matching Zend.

php-src reference

Repro

<?php
try {
    number_format(['x']);
} catch (Throwable $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n";
}
// Zend: TypeError: number_format(): Argument #1 ($num) must be of type float, array given
// vm.php today: no TypeError (silent/wrong path)
./script/docker-exec.sh -- bash -lc '
  php -r "try { number_format([\"x\"]); } catch (Throwable \$e) { echo get_class(\$e),\": \",\$e->getMessage(),PHP_EOL; }"
  php bin/vm.php -r "try { number_format([\"x\"]); } catch (Throwable \$e) { echo get_class(\$e),\": \",\$e->getMessage(),PHP_EOL; }"
'

Scope

Area Files
VM ext/standard/number_format.php
JIT/AOT ext/standard/JitNumberFormat.php
Tests test/compliance/cases/stdlib/number_format_type_error.phpt

Done when

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 apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions