Skip to content

constant() behaves inconsistent when class is undefined #9905

Closed
@AMRoche

Description

@AMRoche

Description

The following code:

<?php

try {
    \constant("\ExistantClass::non_existant_constant");
} catch (\Throwable|\Error|\Exception $e) {
    echo($e->getMessage());
}

Resulted in this output:

⇒  php test.php
PHP Fatal error:  Class "ExistantClass" not found in /Users/alexroche/Desktop/test.php on line 4

Fatal error: Class "ExistantClass" not found in /Users/alexroche/Desktop/test.php on line 4

But I expected this output instead:

"Error : Class "ExistantClass" not found"

(i.e. the error to be caught and the message to be echo'd - what that message is is purely semantics)

PHP Version

8.0.25, 8.1.12

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions