1.2.451. File Is Not Definitions Only

An included file should only provide definitions and declarations, or executable code : not both.

With definitions only files, their inclusion provide new features, and keep the current execution untouched, and in control of the flow. Within this context, globals, use, and namespaces instructions are not considered a warning.

<?php
// This whole script is a file

// It contains definitions and global code
class foo {
    static public $foo = null;
}
//This can be a singleton creation
foo::$foo = new foo();

trait t {}

class bar {}

?>

1.2.451.1. Suggestions

  • Remove the executable code from the file

  • Remove the definitions from the file

1.2.451.2. Specs

Short name

Files/NotDefinitionsOnly

Rulesets

All, Appinfo, CE

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

Very high

Available in

Entreprise Edition, Community Edition, Exakat Cloud