parseUse rebuilt the imported constant name by splitting on the last backslash, but strrpos() returns false for a single-segment name: `use const PHP_EOL;` registered the import as `\HP_EOL` (substr($id, false + 1) drops the first character), and the compiled program failed at runtime with `Undefined constant "HP_EOL"`. $id is already the fully qualified constant name, so store it directly. For multi-segment imports the removed recomposition produced the same value, so their behavior is unchanged.master
parent
b493ac79c5
commit
96ab6a53ef
2 changed files with 33 additions and 5 deletions
@ -0,0 +1,28 @@ |
|||||||
|
--TEST-- |
||||||
|
use const with a single-segment (global) constant name |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
namespace App { |
||||||
|
use const PHP_EOL; |
||||||
|
|
||||||
|
const ANSWER = 42; |
||||||
|
|
||||||
|
function hello(): string |
||||||
|
{ |
||||||
|
return "hello" . PHP_EOL; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
namespace { |
||||||
|
use const App\ANSWER; |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
echo \App\hello(); |
||||||
|
echo ANSWER, "\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
hello |
||||||
|
42 |
||||||
Loading…
Reference in new issue