I want to have an array with objects. For example.
public $aCarObjects = array();
$aCars = array('Audi','BMW','Ford');
foreach($aCars as $car){
array_push($aCarObjects, new Car($car));
}
// Simplified class
class Car implements C{
private $carName;
public function __construct($carName){
$this->carName = $carName;
}
}
interface C {}
This is a very shortened version of what I am trying. The class Car contains some info about the car.
When I am using the Interface C in the Car class. I cannot add objects to the array. Why is that so?
$aCarObjects[] = new Car($car);array_pushisn't the same as$array[]- it only does the same thing in most cases