Forums

Parse error: syntax error, unexpected 'f8a' (T_STRING), expecting ',' or ';'

Hi, I'm having trouble displaying my api info in php. Here's what I'm dealing with. This is my object array:

stdClass Object (
[id] => 65112457-0c13-11e6-a9d9-06e39d13679f
[date_added] => 2016-04-27 00:59:29
[date_modified] => 2016-06-01 17:02:06
[category_id] => 75882edd-cb81-11e5-b35f-066776a6309b
[firstname] => Daniel
[preferred_name] =>
[lastname] => Southwick
[email] => Dan@sonrisepalmdale.com
[phone] => 661-965-9212
[mobile] => 661-965-9212
[admin] => 0
[contact] => 0
[archived] => 0
[deceased] => 0
[volunteer] => 0
[status] => Active [username] => [last_login] => [country] => [timezone] => [picture] => https://secure.gravatar.com/avatar//?default=https%3A%2F%2Fd3600v6qlurvk.cloudfront.net%2Fimg%2Fdefault-avatar.png&size=200&rating=G [family_id] => 486 [family_relationship] => Primary Contact [custom_a167c950-2817-11e6-9f8a-06023090f36d] => Family Ministries Pastor ) 

I can display any field with something simple like:

 echo $data->firstname;

But, when I try the same thing with the custom field I get an error. Ex. 

echo $data->custom_a167c950-2817-11e6-9f8a-06023090f36d;

Here's the error I get:


Parse error: syntax error, unexpected 'f8a' (T_STRING), expecting ',' or ';' in /home/einqui5/public_html/elv.php on line 34


You can see that I'm using the correct ID as listed on the array.


I've tried a million different things and nothing seems to work. Can't find anything online about 'f8a' and I can't imagine what syntax would require a comma or semi-colon at that point in the code.

I'm stumped! Please help!


Hi Anthony.


There's two ways you can go about it.


Basically though, what's happening is in this line,

echo $data->custom_a167c950-2817-11e6-9f8a-06023090f36d;

 It's treating the - symbols as Minus signs, and trying to perform the following:

  

$data->custom_a167c950 - 2817 - 11e6 - 9f8a-06023090f36d;

 This is rather strange for it to be evaluating.


To prevent this, you can do one of the following things.


Put the ID into a string, and use the String as the reference instead.

$field_id = 'custom_a167c950-2817-11e6-9f8a-06023090f36d';
echo $data->$field_id;

 Alternatively, you can convert from a StdObject to an Array, and reference the Array fields.

$arr = (array) $obj;
echo $arr['custom_a167c950-2817-11e6-9f8a-06023090f36d'];

 Hope this helps,

Stewart


That seems so obvious now! Thank you so much!

 


Login or Signup to post a comment