Fixing WackoWiki for PHP 5

For a long time now, I've had a WackoWiki implementation on my (not so technical) personal site. It was upgraded from a WikkaWiki which was installed back in March 2003, which makes it about four months older than this blog :)

Anyway, the point is it's a legacy app, which has never been a problem for a little used website until I discovered (last night) that the hosting company was doing an upgrade on all the servers which would remove PHP 4 to leave only PHP 5. A quick check indicated Wacko R4.2 was supposed to be PHP 5 compatible, so I didn't worry too much about it and went to bed. Of course, when I checked this morning, it was broken, just a blank page...

I downloaded the error log and found a few entries like this:

[error] [client] PHP Catchable fatal error: Object of class Wacko could not be converted to string in wakka/wakka.php on line 254

A quick Google revealed a number of other WackoWiki installs with a similar problem, but also this more useful result which explained the change in PHP 5.2 which was causing the problem:

Changed __toString() to be called wherever applicable. The magic method __toString() will now be called in a string context, that is, anywhere an object is used as a string. The fallback of returning a string that contains the object identifier was dropped in PHP 5.2.0. It became problematic because an object identifier cannot be considered unique. This change will mean that your application is flawed if you have relied on the object identifier as a return value. An attempt to use that value as a string will now result in a catchable fatal error.

Line 254 of wakka.php is:

$cache->Log("Before Run wacko=".$wacko);

I'm not sure what it's supposed to be doing, but it didn't seem too critical, so I just removed the object reference:

$cache->Log("Before Run wacko=");

Seems to work for me!