Identifier Confusions

<?php


const A = 'b::c';

class B {
    static function C() { echo __METHOD__; }
}

//valid call to \B::C()
constant('A')();

// class A not found
//new A;

// Call to undefined function A()
A();

// parse error, this is not supported
//{A}();

Identifiers are used both for constant names and for class names (CITE). Depending on the situation, they may be confused one for the other: here, A is a constant, and its value is accessible for dynamic code purposes. Yet, A() cannot be used.

There is no syntax to call dynamically a function whose name is stored in a constant, without resorting to a call the the constant() function or a temporary variable.

See Also

PHP Features

Last updated: 14 July 2026