Let’s say I have a class file called smallBox.php:
<?php
class SmallBox {
public function boxMethod() {}
}
I then include the smallBox.php file into another class using ‘require’:
<?php
class BigBox {
public function __construct() {
require 'smallBox.php';
$box = new SmallBox();
$box->boxMethod();
}
}
?>
I am new to PHP OOP and MVC and was wondering if including smallBox.php in the BigBox class is considered bad practice?
Instead of manually
require-ing PHP files, you should use autoloading of classes. Basically, it’s a mechanism of loading appropriate PHP files based on a class name.