Bug #70421 [Opn]: Inconsistant constant errors
| From: | cmb@php.net | Date: | Thu, 03 Sep 2015 17:36:36 +0000 |
| Subject: | Bug #70421 [Opn]: Inconsistant constant errors | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-195744@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70421&edit=1
ID: 70421
Updated by: cmb@php.net
Reported by: bensor987 at neuf dot fr
Summary: Inconsistant constant errors
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Irrelevant
PHP Version: 7.0.0RC1
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Using an undefined not namespaced constant is accepted for
backward compatibility reasons, and it will be treated as string,
additionally raising a notice, see <https://3v4l.org/J0R4j>.
When namespaces were introduced, BC was no issue, so the more
correct behavior of raising an error (an Error exception as of PHP
7, respectively) was adopted.
So this is expected behavior, but it seems the documentation has
to be improved.
Previous Comments:
------------------------------------------------------------------------
[2015-09-03 14:59:23] bensor987 at neuf dot fr
"Error Exception", not "Fatal Error". The Fatal Error happens when I don't
catch the Exception, sorry for that.
------------------------------------------------------------------------
[2015-09-03 14:55:39] bensor987 at neuf dot fr
Description:
------------
A Fatal Error "Undefined constant" is triggered when I use a namespace on an undefined
constant, but not when I don't.
Test script:
---------------
<?php
try {
echo \UNDEF_CONSTANT;
} catch (Error $e) {
echo "Fatal Error NS : " . $e->getMessage();
}
try {
echo UNDEF_CONSTANT;
} catch (Error $e) {
echo "Fatal Error w/o NS : " . $e->getMessage();
}
Expected result:
----------------
One of these :
- UNDEF_CONSTANTUNDEF_CONSTANT
- Fatal Error NS : Undefined constant 'UNDEF_CONSTANT'Fatal Error w/o NS : Undefined
constant 'UNDEF_CONSTANT'
Actual result:
--------------
Fatal Error NS : Undefined constant 'UNDEF_CONSTANT'UNDEF_CONSTANT
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70421&edit=1