php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69219 constant() not working with namespace
Submitted: 2015-03-11 11:08 UTC Modified: 2015-03-11 11:12 UTC
From: etienne at crombez dot info Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.6.6 OS: ubuntu utopic 64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: etienne at crombez dot info
New email:
PHP Version: OS:

 

 [2015-03-11 11:08 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-11 11:12 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2015-03-11 11:12 UTC] nikic@php.net
You must use the fully-qualified constant name:

    constant('Foo\Bar::'.$const);

"use" statements are purely compile-time.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 17:01:28 2025 UTC