I am trying to pass an Interface as a constructor parameter
into a class that implements it and calls its method .
file: growth.php
<?php
interface Growth {
public function growPlants():array;
}
file: forest.php
<?php
class Forest implements Growth {
private $growth;
public function __construct(Growth $growth) {
$this->growth = $growth;
}
public function otherFunction():array {
$this->growth->growPlants();
}
}
file: deepforest.php
<?php
class DeepForest implements Growth {
public function growPlants():array {
/* Actions */
}
}
file: test.php
<?php
include "deepforest.php";
include "forest.php";
$deeforest = new DeepForest();
$forest = new Forest($deeforest);
Uncaught Error: Call to undefined method deepForest::otherFunction()