mirror of
https://github.com/php/doc-en.git
synced 2026-03-23 23:32:18 +01:00
Undefined constant throws an error instead of E_NOTICE (#4828)
This commit is contained in:
@@ -907,12 +907,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;
|
||||
}
|
||||
@@ -926,7 +926,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
|
||||
@@ -955,15 +955,6 @@ print "Hello $_GET['foo']";
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
|
||||
<para>
|
||||
When <link linkend="ini.error-reporting">error_reporting</link> is set to
|
||||
show <constant>E_NOTICE</constant> level errors (by setting it to
|
||||
<constant>E_ALL</constant>, for example), such uses will become immediately
|
||||
visible. By default,
|
||||
<link linkend="ini.error-reporting">error_reporting</link> is set not to
|
||||
show notices.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
As stated in the <link linkend="language.types.array.syntax">syntax</link>
|
||||
section, what's inside the square brackets ('<literal>[</literal>' and
|
||||
|
||||
Reference in New Issue
Block a user