Skip to content

Regression: token_name(null) returns UNKNOWN — Zend TypeError (ext/tokenizer/tokenizer.c) #31407

Description

@PurHur

Category

stdlib · php-src-strict

Problem

Under declare(strict_types=1), token_name(null) must TypeError on int $id. VM coerces via toInt() (null→0) and returns 'UNKNOWN'.

Repro Zend 8.2.32 (2026-08-16) VM (2026-08-16)
declare(strict_types=1); token_name(null) TypeError: token_name(): Argument #1 ($id) must be of type int, null given 'UNKNOWN'

Distinct from closed Reflection name drift (#23658) and AOT runtime-int (#27278). Reflection still leaves $id untyped on VM (optional follow-up).

php-src reference

PHP implementation target

  • ext/tokenizer/token_name.php — replace bare toInt() with InternalStrictArg / shared int-arg guard under strict_types; ext/tokenizer/JitTokenName.php / JitLongArg must TypeError on null (not coerce); no new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_token_name_null.php'
# expect TypeError (match host `php test/repro/maintainer_gap_token_name_null.php`)
<?php
declare(strict_types=1);
token_name(null);

Done when

  • Under strict_types, token_name(null)TypeError: … Argument #1 ($id) must be of type int, null given (VM + JIT/AOT when in scope)
  • Does not return 'UNKNOWN' for this case
  • Compliance or unit guard under test/compliance/cases/ or targeted PHPUnit
  • php-src-strict; no php-compiler-strict shortcut

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 machinebugSomething isn't workingimplementation-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