[ciapug] PHP 5.2.x : __toString stuff

David Champion dchampion at visionary.com
Fri Nov 21 14:25:29 CST 2008


I ran across an issue in an existing system, where a server got upgraded 
to PHP 5.2.0 from 5.1.4, and it started throwing this error:

"Catchable fatal error: Object of class stdClass could not be converted 
to string in.."

Here's a thread that explains and / or complains about the issue:

http://bugs.php.net/bug.php?id=41221

In my case, I was able to do a quick fix - it was referencing the ADODB 
result set's method FetchField like this:

$field = $this->results->FetchField($col);

I changed it to this:

$field = $this->results->FetchField[$col];

... and it fixed the issue, since it's now returning the array element 
instead of making a function call that returns a string.

Anyway, just something some of you may need to look out for when 
upgrading PHP. Looking around for solutions, I saw that this affects 
various 3rd party apps & libraries like forums and shopping cart 
applications, so... be sure and test before you upgrade.

Somewhere along the way, among some documentation about __toString() and 
the other "magic functions", there was a mention that this behavior may 
change in the future too.

-dc




More information about the ciapug mailing list