Question

I have a function that returns an array and I'm trying to call a certain value from it like so

echo $this->getName()['first']. ' ' .$this->getName()['last'];

getName function...

protected function getName(){
    return $this->user;
}

the array is laid out like so...

$this->user = array(
    'id' => $id,
    'first' => $fn,
    'last' => $ln
);

This works on localhost but not on my production server. I'm guessing it has something to do with my php.ini but not sure. Any help appreciated.

Était-ce utile?

La solution

Your question is tagged PHP 5.3, but this syntax is only valid in 5.4.

Look here

Also, if you develop on a Mac, please be aware that OSX Mavericks upgraded the local version of PHP from 5.3 to 5.4.

Cheers

Autres conseils

Well, the first thing to look at is the PHP version your production server is using. Maybe your production server is using an old PHP version.

On a side note, why would you call the same function twice? I mean, why not doing something like

$user = $this->getName();
echo $user['first'] . " " . $user['last'];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top