From 0d7481cf4553232494540cc03dab783ec6dcd43e Mon Sep 17 00:00:00 2001 From: Takuya Aramaki Date: Wed, 13 Aug 2025 22:45:54 +0900 Subject: [PATCH] Undefined constant throws an error instead of E_NOTICE --- language/types/array.xml | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/language/types/array.xml b/language/types/array.xml index 98a18a2766d5..8a4c34e0fc8e 100644 --- a/language/types/array.xml +++ b/language/types/array.xml @@ -902,12 +902,12 @@ $arr = array('fruit' => 'apple', 'veggie' => 'carrot'); echo $arr['fruit'], PHP_EOL; // apple echo $arr['veggie'], PHP_EOL; // carrot -// Incorrect. This works but also throws a PHP Error because +// Incorrect. This does not work and throws a PHP Error because // of an undefined constant named fruit // // Error: Undefined constant "fruit" try { - echo $arr[fruit]; // apple + echo $arr[fruit]; } catch (Error $e) { echo get_class($e), ': ', $e->getMessage(), PHP_EOL; } @@ -921,7 +921,7 @@ echo $arr['fruit'], PHP_EOL; // apple echo $arr[fruit], PHP_EOL; // carrot // The following is okay, as it's inside a string. Constants are not looked for -// within strings, so no E_NOTICE occurs here +// within strings, so no error occurs here echo "Hello $arr[fruit]", PHP_EOL; // Hello apple // With one exception: braces surrounding arrays within strings allows constants @@ -950,15 +950,6 @@ print "Hello $_GET['foo']"; - - When error_reporting is set to - show E_NOTICE level errors (by setting it to - E_ALL, for example), such uses will become immediately - visible. By default, - error_reporting is set not to - show notices. - - As stated in the syntax section, what's inside the square brackets ('[' and