[doc-en] master: Undefined constant throws an error instead of E_NOTICE (#4828)

From: Date: Fri, 03 Oct 2025 15:13:45 +0000
Subject: [doc-en] master: Undefined constant throws an error instead of E_NOTICE (#4828)
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-22783@lists.php.net to get a copy of this message
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

« previous php.doc.cvs (#22783) next »