1.2.397. Dynamically Called Classes

This rule reports when a class is called dynamically. To call dynamically a class, one must use a variable at instantiation time, or with the objects syntaxes.

<?php

// This class is called dynamically
class X {
    const CONSTANTE = 1;
}

$classe = 'X';

$x = new $classe();

echo $x::CONSTANTE;

?>

1.2.397.1. Specs

Short name

Classes/VariableClasses

Rulesets

All, Appinfo, CE, Changed Behavior

Exakat since

0.8.4

PHP Version

All

Severity

Time To Fix

Precision

Very high

Features

class, dynamic-class

Available in

Entreprise Edition, Community Edition, Exakat Cloud