I am attempting to use the following PHP class:
<?php
class Service {
public $code, $description;
public static $services = array(
"A" => "Shipping",
"B" => "Manufacturing",
"C" => "Legal",
"D" => "Accounts Receivable",
"E" => "Human Resources",
"F" => "Security",
"G" => "Executive",
"H" => "IT"
);
public function _construct( $c, $d) {
$this->code = $c;
$this->description = $d;
}
public static function getDescription( $c ){
return $services[$c];
}
public static function generateServiceList() {
$service_list[] = array();
foreach ($services as $k => $v ){
$service_list[] = new Service( $k, $v );
}
return $service_list;
}
}
?>
…in the following way:
<?php
$services = Service::generateServiceList();
?>
…but getting the following error:
Warning: Invalid argument supplied for foreach() in /classes/service.php on line 31
Any idea why? Is this some kind of an access issue? Thanks.
$servicesis undefined. Did yu meanself::$services?