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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 22:01:28 2024 UTC