Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an array from Amazon's API, which I'm iterating. When I try to echo or print() one of the values I get an "Array to string conversion" error.

The value in question is a string, which I've confirmed with var_dump().

Is this a bug in PHP v.5.5.8(-1~dotdeb.1) or am I going crazy?

This is the line of code that causes the hangup (using Blade, but this is the produced PHP):

<td><a href='http://<?php echo $instance['PublicDnsName']; ?>' target='_blank'><?php echo $instance['PublicDnsName']; ?></a></td>

I'm on Ubuntu Server via Vagrant, under Windows 7 as host OS.

EDIT: If I print_r() the value, it works fine, but it appends a "1" to the output.

EDIT2: It seems to be an issue with Blade, perhaps, as I can echo the value normally within my controller class instead of in the view/template. I'm using Laravel 4 and its Blade templating engine.

EDIT3: Here is the relevant portion of my Blade template: <td><a href='{{ $instance['PublicDnsName'] }}' target='_blank'>{{ $instance['PublicDnsName'] }}</a></td>

This is inside a nested foreach loop.

The big data array comes from Amazon's EC2, thusly:

$data = $this->ec2->DescribeInstances()->getAll(); As mentioned earlier, if I print this out within the controller, it will print the string correctly without errors.

I also tried it with normal PHP tags, without the Blade specific syntax, but it yields the same result.

share|improve this question
    
try a print_r($var) so if it's an array really you could see the output as of an array, if not put your var_dump() here –  ManZzup Jan 28 at 11:33
    
Could you also show code, how do you var_dump etc. and results including full error messages and rendered html? Description is usually just not enough. A phpfiddle could be helpful too. –  dragoste Jan 28 at 11:33
    
echo '<pre>'; print_r($instance['PublicDnsName']); echo '</pre>'; ...prints: ec2-xx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com echo '<pre>'; var_dump($instance['PublicDnsName']); echo '</pre>'; ...prints: string(50) "ec2-xx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com" –  ThePaavero Jan 28 at 11:38
    
Bit of a stab in the dark... Have you tried doing this outside of blade? I.e into a normal php file, I'm not familiar with blade but could it be causing the problem? –  jd182 Jan 28 at 11:47
    
jd181: No, but I seem to be able to echo it out within the controller, so Blade could have something to do with it. Thanks! –  ThePaavero Jan 28 at 11:50

1 Answer 1

Solved: I'm an idiot. The AWS API returns both a string OR an array with just the value 1. So, no bug anywhere. Thanks for the help!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.