I have two classes ServiceDetails
and AvailableServices
class ServiceDetails {
private $service_name;
private $price;
private $currency_id;
public function __construct($service_name, $price, $currency_id) {
$this->service_name = $service_name;
$this->price = $price;
$this->currency_id = $currency_id;
}
}
class AvailableServices {
public $services;
public function __construct() {
$this->services = [];
}
}
I created an instance of AvailableServices
and added an object of class ServiceDetails
into the $services
array of the AvailableServices
instance.
$services = new AvailableServices();
$service_details = new ServiceDetails($a, $b, $c);
$services->services[] = clone $service_details;
I var_dump
the $services
object and it outputs correctly. However, when I do json_encode
, nothing outputs except the services
property of AvailableServices
.
var_dump($services); // something
echo json_encode($services); // nothing