php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65560 defined and constant does not resolve use aliases
Submitted: 2013-08-26 13:56 UTC Modified: 2013-08-26 14:16 UTC
From: codronm+circlecode at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.5.3 OS: linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: codronm+circlecode at gmail dot com
New email:
PHP Version: OS:

 

 [2013-08-26 13:56 UTC] codronm+circlecode at gmail dot com
Description:
------------
while var_dump resolves correctly aliases defines by the use keyword, defined and constant functions does not resolve it.

Test script:
---------------
<?php
 
namespace Foo;
 
class Bar {
const baz = 'baz';
}
 
function test($const){
if(defined($const)){
echo "$const value is ". constant($const) . "\n";
} else {
echo "$const is not defined" . "\n";
}
}
 
use \Foo\Bar as Bar;
 
var_dump(\Foo\Bar::baz);
test("\Foo\Bar::baz");
var_dump(Bar::baz);
test("Bar::baz");

Expected result:
----------------
string(3) "baz"
\Foo\Bar::baz value is baz
string(3) "baz"
Bar::baz is not defined

Actual result:
--------------
string(3) "baz"
\Foo\Bar::baz value is baz
string(3) "baz"
Bar::baz value is baz

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-26 14:09 UTC] codronm+circlecode at gmail dot com
Sorry, I have inverted Expected result and actual result… I don't know how to edit this
 [2013-08-26 14:09 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-08-26 14:09 UTC] nikic@php.net
Names in strings always need to be fully qualified. Aliases do not apply to them. (And they can't, because aliases are local to the file, but the string with the name can be used completely elsewhere.)
 [2013-08-26 14:16 UTC] codronm+circlecode at gmail dot com
So thanks for the point, and sorry for the "noise".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 03:01:31 2025 UTC