1.2.388. Dynamic Class Constant

This is the list of dynamic calls to class constants.

Constant may be dynamically called with the constant() function. In PHP 8.3, they may also be called with a new dedicated syntax.

<?php
    // Dynamic access to 'E_ALL'
    echo constant('E_ALL');

    interface i {
        const MY_CONSTANT  = 1;
    }

    // Dynamic access to 'E_ALL'
    $constantName = 'MY_CONSTANT';
    echo constant('i::'.$constantName);

    // With PHP 8.3 :
    echo i::{$constantName};

?>

1.2.388.1. Specs

Short name

Classes/DynamicConstantCall

Rulesets

All, Appinfo, CE

Exakat since

0.8.4

PHP Version

All

Severity

Time To Fix

Precision

Very high

Features

dynamic-constant

Available in

Entreprise Edition, Community Edition, Exakat Cloud