-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
constant() behaves inconsistent when class is undefined #9905
Comments
If you are referring to a non-existant class, that results in a fatal error ( Anyhow, as is, this is not a bug. We could treat this as feature request to change the fatal error to an |
Hi @cmb69 - Honestly, whatever y'all think is best is fine by me, but then at the very least the documentation for constant() is misleading (https://www.php.net/manual/en/function.constant) as it states an Error will be thrown if the constant doesn't exist (which logically if the class doesn't it won't), and that it also works with class constants. In addition there's the following;
|
Hmm, given that other cases of undefined classes throw an |
Directly referring to a constant of an undefined throws an exception; there is not much point in `constant()` raising a fatal error in this case.
* PHP-8.1: Fix GH-9905: constant() behaves inconsistent when class is undefined
* PHP-8.2: Fix GH-9905: constant() behaves inconsistent when class is undefined
…n first to avoid hard crash (Alex Henderson-Roche) This PR was merged into the 2.x branch. Discussion ---------- Updates CoreExtension::twig_constant to check for definition first to avoid hard crash The behaviour of PHP's constant() method has been updated after php/php-src#9905 was accepted and fixed in PHP 8.1 (and previously changed post PHP 8.0) . This PR prevents a fatal error in the case a constant is supplied that doesn't actually exist. Commits ------- 56b3122 Updates CoreExtension::twig_constant to check for definition first to avoid hard crash
Description
The following code:
Resulted in this output:
But I expected this output instead:
(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
The text was updated successfully, but these errors were encountered: