Bug #77628 [Com]: Using const AND use in the same scope.
| From: | dams@php.net | Date: | Sun, 17 Feb 2019 10:36:13 +0000 |
| Subject: | Bug #77628 [Com]: Using const AND use in the same scope. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219611@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77628&edit=1
ID: 77628
Comment by: dams@php.net
Reported by: dams@php.net
Summary: Using const AND use in the same scope.
Status: Open
Type: Bug
Package: *Programming Data Structures
Operating System: Irrelevant
PHP Version: 7.3.2
Block user comment: N
Private report: N
New Comment:
Yes to both comments.
When C is defined in the global space (in the example), it works as expected.
The error message mentions C, which is confusing with D.
Previous Comments:
------------------------------------------------------------------------
[2019-02-17 10:21:13] requinix@php.net
It took me a second to understand but the code is correct. @dams is talking specifically about the
error message (which points to the "echo D" line) saying "C" when it would be
better if it said "D".
------------------------------------------------------------------------
[2019-02-17 10:19:23] nikic@php.net
Uses are always relative to the root namespace, you are looking for "use const A\C as D".
------------------------------------------------------------------------
[2019-02-17 10:10:05] dams@php.net
Description:
------------
Using an import alias and defining the constant in the same scope leads to inconsistent error
message : Undefined constant 'C'
C is aliased into D first.
Then it is created.
Its creation is validated by 'echo C', which yields the right value.
'echo D' fails, mentioning that 'C' doesn't exists.
Extra note :
+ splitting the namespace A in two (one with const, one with use) raise the same issue.
+ use and const may be in any order (use first, const first), still raise the same issue.
Test script:
---------------
<?php
namespace A {
use const C as D;
const C = 2;
echo C;
echo D;
}
Expected result:
----------------
22
Actual result:
--------------
2PHP Fatal error: Uncaught Error: Undefined constant 'C' in test.php:8
Stack trace:
#0 {main}
thrown in test.php on line 8
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77628&edit=1