Thursday, 8 August 2013

Catchable fatal error: Object could not be converted to string - but var_dump says it IS a string

Catchable fatal error: Object could not be converted to string - but
var_dump says it IS a string

I have a problem that was already asked by a lot of people here: when
trying to echo a string, "Catchable fatal error: Object of class Struct
could not be converted to string in
D:\Programy\XAMP\htdocs\e-history\test.php on line 30". For most related
questions, trying var_dump() function was suggested. However, I tried this
and everything seems to be OK, except for it throws the error.
My code (testing version):
$place = Struct::factory('gid','lat','lon','radius');
$places = loadPlaces('', 50, 14);
$j = 0;
var_dump($places[$j]->gid);
echo "$places[$j]->gid";
The output of var_dump and echo is as follows:
string(1) "6"
Catchable fatal error: Object of class Struct could not be converted to
string in D:\Programy\XAMP\htdocs\e-history\test.php on line 30
Usually there are no problems with $object->value notation, and I don't
know why it doesn't work in this case. I had some problems with
array/object mismatches, but I'm almost sure it's not this case. Any idea
how to solve it?

No comments:

Post a Comment