|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 02:00:01 2025 UTC |
You must use the fully-qualified constant name: constant('Foo\Bar::'.$const); "use" statements are purely compile-time.