How can one effectively access $this->conf in a PHP class without repeating the require statement?

When working in a PHP class, accessing $this->conf without repeating the require statement can be achieved by using dependency injection. By passing the configuration object as a parameter in the class constructor, you can access it within the class without needing to require it again. This approach follows the principle of dependency injection, making the code more modular and easier to test.

class MyClass {
    private $conf;

    public function __construct($conf) {
        $this->conf = $conf;
    }

    public function someMethod() {
        // Access $this->conf here without requiring it again
    }
}

// Require configuration file
require 'config.php';

// Create an instance of MyClass with the configuration object passed in
$myClass = new MyClass($conf);

// Access $this->conf within the class methods
$myClass->someMethod();