Skip to content

Language: INF/NAN→int conversion silent — Zend E_DEPRECATED (zend_operators.c) #27926

Description

@PurHur

Category

Language · php-src-strict · float→int deprecation · non-finite

Problem

Zend emits E_DEPRECATED: Implicit conversion from float INF to int loses precision when INF/NAN are coerced to int in untyped contexts (bitwise ops, array dim read/write), then continues with a truncated value. VM/JIT already emit that deprecation for finite non-integral floats (1.5) but stay silent for non-finite values — VmMath::floatLosesIntPrecision() returns false when !is_finite($value).

Related but separate from typed-int TypeError (#27925).

Repro (2026-08-05, Zend 8.2.32 / HEAD a2b5d7e5b) Zend VM / JIT
error_reporting(E_ALL); INF | 1 E_DEPRECATED then 1 1 (no deprecation)
$a=[1,2,3]; $a[INF] E_DEPRECATED then 1 ($a[0]) 1 (no deprecation)
1.5 | 2 (control) E_DEPRECATED then 3 same (OK)

php-src reference

PHP implementation target

  • ext/standard/VmMath.phpfloatLosesIntPrecision() / warnFloatToIntPrecisionLoss(): treat non-finite like Zend (emit the same E_DEPRECATED message with INF/NAN/-INF text), or mirror php-src’s exact branch for non-finite before truncate
  • Call sites already using warnFloatToIntPrecisionLoss (bitwise, dim) pick this up; audit dim-write path
  • Keep typed weak coerce as TypeError (Language: weak typed int accepts INF/NAN — Zend TypeError (zend_operators.c zend_dval_to_lval_safe) #27925) — deprecation is the untyped path only
  • PHP-in-PHP only

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/inf_to_int_deprecated.php <<'"'"'PHP'"'"'
<?php
error_reporting(E_ALL);
set_error_handler(function (int $no, string $msg): bool {
  if ($no === E_DEPRECATED) { echo "DEPRECATED:", $msg, "\n"; return true; }
  return false;
});
echo "bit:", (INF | 1), "\n";
$a = [1, 2, 3];
echo "dim:", $a[INF] ?? "miss", "\n";
PHP
php /tmp/inf_to_int_deprecated.php
php bin/vm.php /tmp/inf_to_int_deprecated.php
php bin/jit.php /tmp/inf_to_int_deprecated.php'

Expected Zend:

DEPRECATED:Implicit conversion from float INF to int loses precision
bit:1
DEPRECATED:Implicit conversion from float INF to int loses precision
dim:1

Done when

Trust snapshot (this maintainer run)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions