Skip to content

Commit 094816b

Browse files
authored
Undefined constant throws an error instead of E_NOTICE (#4828)
1 parent 9b09581 commit 094816b

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

language/types/array.xml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -907,12 +907,12 @@ $arr = array('fruit' => 'apple', 'veggie' => 'carrot');
907907
echo $arr['fruit'], PHP_EOL; // apple
908908
echo $arr['veggie'], PHP_EOL; // carrot
909909
910-
// Incorrect. This works but also throws a PHP Error because
910+
// Incorrect. This does not work and throws a PHP Error because
911911
// of an undefined constant named fruit
912912
//
913913
// Error: Undefined constant "fruit"
914914
try {
915-
echo $arr[fruit]; // apple
915+
echo $arr[fruit];
916916
} catch (Error $e) {
917917
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
918918
}
@@ -926,7 +926,7 @@ echo $arr['fruit'], PHP_EOL; // apple
926926
echo $arr[fruit], PHP_EOL; // carrot
927927
928928
// The following is okay, as it's inside a string. Constants are not looked for
929-
// within strings, so no E_NOTICE occurs here
929+
// within strings, so no error occurs here
930930
echo "Hello $arr[fruit]", PHP_EOL; // Hello apple
931931
932932
// With one exception: braces surrounding arrays within strings allows constants
@@ -955,15 +955,6 @@ print "Hello $_GET['foo']";
955955
</programlisting>
956956
</informalexample>
957957

958-
<para>
959-
When <link linkend="ini.error-reporting">error_reporting</link> is set to
960-
show <constant>E_NOTICE</constant> level errors (by setting it to
961-
<constant>E_ALL</constant>, for example), such uses will become immediately
962-
visible. By default,
963-
<link linkend="ini.error-reporting">error_reporting</link> is set not to
964-
show notices.
965-
</para>
966-
967958
<para>
968959
As stated in the <link linkend="language.types.array.syntax">syntax</link>
969960
section, what's inside the square brackets ('<literal>[</literal>' and

0 commit comments

Comments
 (0)