1.2.975. Php7 Relaxed Keyword

Most of the traditional PHP keywords may be used inside classes, enums, traits and interfaces: they can be used as constant or method name.

It is recommended to use this syntax cautiously, as it leads to a lot of surprises and confusion from unususpecting developpers.

This was not the case in PHP 5, and will yield parse errors.

<?php

// Compatible with PHP 7.0 +
class foo {
     const array = [];

    // as is a PHP 5 keyword
    public function as() {
     print_r(self::array);
    }
}

?>

See also Loosening Reserved Word Restrictions.

1.2.975.1. Specs

Short name

Php/Php7RelaxedKeyword

Rulesets

All, Appinfo, CE, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56

Exakat since

0.8.4

PHP Version

With PHP 7.0 and more recent

Severity

Major

Time To Fix

Slow (1 hour)

Precision

Very high

Features

keyword, reserved-name

Related rule

No Keyword In Namespace

Available in

Entreprise Edition, Community Edition, Exakat Cloud