I've written a class which in the construct accesses the db and gets a list of names. These names go into an associative array e.g. ('name' => 'id'). 

i.e. the point is to pass in the name to get back an ID:

```
$id = names::nameToId('some name');
print $id;
// prints int

```

The problem is when I try and return the array from the construct I get an error:

> 
> Notice: Undefined variable: nameArray in (etc)
> 
> 
> 

Here is the code so far:

```
class nameToId {
    public $nameArray;
    private $mysqli;

    public function __construct($mysqli) {
        ...
        while($row = mysqli_fetch_assoc($res)) {
            $nameArray[$row['name']] = $row['id'];
        }

        return $nameArray;
    }

    static public function nameToId($name) {
        $nameId = $nameArray[$name];
        return $nameId;
    }
}

$namesToId = new nameToId($mysqli);
$nameId = $namesToId::nameToId('some name');
echo $nameId;

```

Why doesn't $nameArray get passed to nameToId()? I'm new to classes, and I thought by declaring $nameArray as public when I first create the class that it would make it available. I have also tried to make it global even though I know that is not good form but even still it didn't work.