Bug #69219 [Opn->Nab]: constant() not working with namespace
| From: | nikic@php.net | Date: | Wed, 11 Mar 2015 11:12:22 +0000 |
| Subject: | Bug #69219 [Opn->Nab]: constant() not working with namespace | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191307@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69219&edit=1
ID: 69219
Updated by: nikic@php.net
Reported by: etienne at crombez dot info
Summary: constant() not working with namespace
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: ubuntu utopic 64
PHP Version: 5.6.6
Block user comment: N
Private report: N
New Comment:
You must use the fully-qualified constant name:
constant('Foo\Bar::'.$const);
"use" statements are purely compile-time.
Previous Comments:
------------------------------------------------------------------------
[2015-03-11 11:08:27] etienne at crombez dot info
Description:
------------
constant does not work when using constant class with a class defined in a use statement.
Test script:
---------------
//Foo/Bar.php
namespace Foo;
class Bar
{
const toto=42;
}
// index.php
use Foo\Bar;
$const = 'toto';
print constant('Bar::'.$const);
//PHP Warning: constant(): Couldn't find constant
Expected result:
----------------
42
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69219&edit=1