[DOC-CVS] [doc-en] master: Undefined constant throws an error instead of E_NOTICE (#4828)
[email protected] (Takuya Aramaki via GitHub)
| Newsgroups | php.doc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: Takuya Aramaki (takaram)
Committer: GitHub (web-flow)
Pusher: Crell
Date: 2025-10-03T10:13:42-05:00
Commit: https://github.com/php/doc-en/commit/094816bd170e26abf0e057dae1cfb498dd6aad88
Raw diff: https://github.com/php/doc-en/commit/094816bd170e26abf0e057dae1cfb498dd6aad88.diff
Undefined constant throws an error instead of E_NOTICE (#4828)
Changed paths:
M language/types/array.xml
Diff:
diff --git a/language/types/array.xml b/language/types/array.xml
index 8338dd20fd09..78b2ac8f21e5 100644
--- a/language/types/array.xml
+++ b/language/types/array.xml
@@ -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