Skip to content

Regression: Reflection DNF/(int\|null) type strings diverge from Zend (ext/reflection/php_reflection.c) #23065

Description

@PurHur

Category

Regression · php-src-strict · language · Reflection · pillar 4

Problem

ReflectionType::__toString() (via (string)$type) diverges from Zend for two cases that already parse/compile:

  1. DNF parentheses — Zend keeps grouping parens around an intersection in a union; VM drops them.
  2. int|null normalization — Zend stringifies int|null as ?int; VM keeps int|null (?int shorthand still matches).

Verified 2026-07-25 (host Zend PHP 8.2.32 vs php bin/vm.php):

Repro Zend 8.2+ VM
(string) of (Traversable&Countable)|array param (Traversable&Countable)|array Traversable&Countable|array (parens missing)
(string) of int|null param ?int int|null
(string) of ?int param ?int ?int (same)

php-src reference

PHP implementation target

  • Reflection type __toString / name rendering in ext/reflection (PHP) — emit Zend-identical DNF parentheses and ?T for single-named |null unions
  • PHP-in-PHP; no new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/reflect_type_str.php <<'"'"'PHP'"'"'
<?php
function f((Traversable&Countable)|array $x) {}
function g(int|null $x) {}
function h(?int $x) {}
echo (string)(new ReflectionFunction("f"))->getParameters()[0]->getType(), "\n";
echo (string)(new ReflectionFunction("g"))->getParameters()[0]->getType(), "\n";
echo (string)(new ReflectionFunction("h"))->getParameters()[0]->getType(), "\n";
PHP
php bin/vm.php /tmp/reflect_type_str.php
# expect:
# (Traversable&Countable)|array
# ?int
# ?int

Done when

  • DNF union string includes Zend parentheses around the intersection group
  • int|null (and null|int) stringifies as ?int
  • Compliance .phpt under test/compliance/cases/reflection/
  • 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: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