I’m starting to study the “dipendency injection”, and i would like start this practice in my project but i’m having some troubles.
I’m creating a custom CMS, and i have a class called “Address”. As obvious, this class interact with the addresses of customer.
That’s provide also to get the city of customer with the costal pode provided. I need an external API to do this, and i decide to integrate a Guzzle for interact with the Api that permits me to acces to this info.
So i thought inject this class in the constructor of my Address class, in this way:
namespace AppAddress;
use GuzzleHttp;
Class Address {
private $client;
public function __construct(GuzzleHttpClient $client) {
$this->client = $client;
}
where i will do the istance in my index.php, in this way:
<?PHP
use AppAddressAddress;
$address = new Address();
But i still get the error:
Fatal error : Uncaught ArgumentCountError: Too few arguments to function AppAddressAddress::__construct(), 0 passed
I would like have a explication on this, and if i’m using correctly the concept of dipendency injection. Thank you!