I'm a bit confused as to what you want that array to be. Additionally, the 2nd method (which I think you want to be named "getJobs()"?) cannot have multiple return statements as you have used, as the function will terminate upon completion of the first return. You will probably have to instead use one return which returns an array.
In any case, I think you need to rethink things a bit. What I would probably do is have a Casting class which only has a single-dimension array of attributes for one casting object. Then if you want to group castings together, that would be a separate class/object which has an array of Casting objects. One possible approach:
<?php
/**
* Defines a single job
*/
class CastingJob
{
private $job = array(
"job_id" => 0,
"listed_on" => '',
"expiration" => '',
"location" => '',
"gender" => '',
"age" => '',
"categories" => '',
"union" => '',
"rate" => '',
"email" => '',
"description" => ''
);
public function __construct(
$job_id = 0,
$listed_on = '',
$expiration = '',
$location = '',
$gender = '',
$age = '',
$categories = '',
$union = '',
$rate = '',
$email = '',
$description = '')
{
foreach(array_keys($this->job) as $key)
{
if(isset($$key))
{
$this->job[$key] = $$key;
}
}
}
public function __set($key, $value)
{
if(array_key_exists($key, $this->job))
{
$this->job[$key] = $value;
}
else
{
throw new Exception("Invalid key '$key'");
}
return true;
}
public function __get($key)
{
if(array_key_exists($key, $this->job) === false)
{
throw new Exception("Invalid key '$key'");
}
return ($this->job[$key]);
}
}
/**
* Defines a grouping of related CastingJob objects
*/
class CastingGroup
{
private $jobs = array();
public function addJob(CastingJob $cj)
{
$this->jobs[$cj->job_id] = $cj;
}
public function getJob($job_id)
{
if(array_key_exists($job_id, $this->jobs))
{
return $this->jobs[$job_id];
}
else
{
user_error("Invalid job id '$job_id'");
return false;
}
}
}
// sample usage:
$cg = new CastingGroup();
$cg->addJob(new CastingJob(1,'aa','bb','cc','dd','ee','ff','gg','hh','ii','jj'));
$cg->addJob(new CastingJob(2,'kk','ll','mm','nn','oo','pp','qq','rr','ww','tt'));
echo $cg->getJob(2)->location; // outputs "mm"