Jump to content

trying to access an array's values, but can't.


ballhogjoni

Recommended Posts

I have the following code:

$user->attributes()["username"]

 

$user->attributes() is an array of the users attributes. array('username' => 'value')

 

when i run this code: $user->attributes()["username"] i get an error:

Parse error: parse error in ...

 

What am i doing wrong?

The problem is that you cannot chain array access in the form of [2] after a function call (which is fixed in a future version of PHP, as noted).

 

The easiest way to do this is to simply make a getAttribute function on that class which would do $obj->getAttribute("username");

If it is not php 5.4 then you can't use array dereferencing.  Store it in a variable and acccess it like that.

Ok thanks this is what I didn't want to do ... running php 5.3 ... looks like i don't have a choice unless i upgrade.

 

The problem is that you cannot chain array access in the form of [2] after a function call (which is fixed in a future version of PHP, as noted).

 

The easiest way to do this is to simply make a getAttribute function on that class which would do $obj->getAttribute("username");

Ok thanks! I will do this, easiest way to handle it. Don't want to have to keep making variables every time I want to access the array.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.