Skip to content

Incorrect result with reflection in low-trigger JIT #16572

Closed
@YuanchengJiang

Description

@YuanchengJiang

Description

The following code:

<?php
$fusion=[1, 2];
function dumpType(ReflectionType $rt, int $indent = 0) {
        $str_indent = str_repeat(' ', 2 * $indent);var_dump($str_indent);
    echo $str_indent . "Type $rt is " . $rt::class . ":\n";
    echo $str_indent . "Allows Null: " . json_encode($rt->allowsNull()) . "\n";var_dump($str_indent);
    foreach ($rt->getTypes() as $type) {
        if ($type instanceof ReflectionNamedType) {
            echo $str_indent . "  Name: " . $type->getName() . "\n";var_dump($str_indent);
            echo $str_indent . "  String: " . (string) $type . "\n";var_dump($str_indent);
        } else {
            dumpType($fusion, $indent+1);var_dump($fusion);
        }
    }
}
function test1(): (X&Y)|(Z&Traversable)|null { }
dumpType((new ReflectionFunction('test1'))->getReturnType());

Resulted in this output (with JIT 1215):

Fatal error: Uncaught TypeError: Cannot use "::class" on null

But I expected this output instead:

Fatal error: Uncaught TypeError: dumpType(): Argument #1 ($rt) must be of type ReflectionType, null given

This could potentially lead to segfault.

PHP Version

nightly

Operating System

ubuntu 22.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions