1.2.726. Multiple Classes In One File

It is regarded as a bad practice to store several classes in the same file. This is usually done to make life of __autoload() easier.

It is often unexpected to find class foo in the bar.php file. This is also the case for interfaces and traits.

One good reason to have multiple classes in one file is to reduce include time by providing everything into one nice include.

<?php

// three classes in the same file
class foo {}
class bar {}
class foobar{}

?>

See also Is it a bad practice to have multiple classes in the same file?.

1.2.726.1. Suggestions

  • Split the file into smaller files, one for each class

1.2.726.2. Specs

Short name

Classes/MultipleClassesInFile

Rulesets

All, Appinfo, CE, Coding conventions

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

class

Available in

Entreprise Edition, Community Edition, Exakat Cloud