June 2017
Intermediate to advanced
536 pages
9h 49m
English
Throughout the introductory section, we touched upon passing dependency through the class __construct() method. There is more to it than just passing the dependent object. Let's consider the following three seemingly similar but different examples.
Though PHP has been supporting type hinting for quite a while now, it isn't uncommon to come across pieces of code, which are as follows:
<?phpclass App{ protected $config; protected $logger; public function __construct($config, $logger) { $this->config = $config; $this->logger = $logger; } public function run() { $this->config->setValue('executed_at', time()); $this->logger->log('executed'); }}class Config{ protected $config = []; public function setValue(