php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70421 Inconsistant constant errors
Submitted: 2015-09-03 14:55 UTC Modified: 2015-09-06 17:03 UTC
From: bensor987 at neuf dot fr Assigned: cmb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.0RC1 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bensor987 at neuf dot fr
New email:
PHP Version: OS:

 

 [2015-09-03 14:55 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-03 14:59 UTC] 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 17:36 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2015-09-03 17:36 UTC] cmb@php.net
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.
 [2015-09-03 17:36 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2015-09-06 17:02 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=337760
Log: undefined qualified constants raise a fatal error (fixes #70421)
 [2015-09-06 17:03 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2015-09-06 17:03 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 15:01:28 2024 UTC