Skip to content

new $class with the name of a class that does not exist returns null instead of throwing Error #565

Closed

Description

@blacktrs

Summary

new $class with the name of a class that does not exist returns null instead of throwing Error.

Repro

<?php
function make(string $class) { return new $class(1); }
class Known { public function __construct(public int $a) {} }
echo make('Known')->a, "\n";
try {
    var_dump(make('NoSuchClass'));
} catch (Error $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n";
}

Expected (php)

1
Error: Class "NoSuchClass" not found

Actual (manticore dafdd5fa, Darwin arm64)

1
float(0)

Tracking

Known-bug repro: tests/aot/repro/wrong/new_dyn_unknown_class_returns_null.php — bash tests/aot/xfail.sh -k new_dyn_unknown_class_returns_null reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    on Nov 3, 2026
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

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions