Running drupal 6.22 on PHP 5.1

Upgrading this site to the latest 6.x release of Drupal seemed to go fine, but I started to get emails warning of cron failures. The specific error being recorded was

Fatal error: Call to undefined function json_decode() in myhostingpath/sites/all/modules/twitter/twitter.lib.php on line 258

Now, although I'd forgotten I'd even got a twitter account or that I'd got a twitter module installed, I assumed that disabling the module in mentioned would just have thrown a similar error for another module. So best to fix the problem.

So in the interests of helping anyone else who's (googled for and) got this problem here's how I've fixed it:

Some google seaching threw up the reason - json_decode is part of PHP from 5.2.0 onwards. Not ideal if your webhost is still running something older. Further googling found a suggested solution in a wrapper module.

Here's how I've applied it to Drupal 6:
- Download the jsonwrapper from this website
- Unzip/whatever & upload to your Drupal includes directory so that the jsonwrapper directory is in includes
- Open up to edit /includes/bootstrap.inc and add the following line immediately after the first comment lines (about line 8)
include_once("jsonwrapper/jsonwrapper.php");
- Save the file

As a test, hit the cron URL (http://yoursite/cron.php). If this returns blank - success !

These days Drupal discourage putting anything in the 'core' directory structure (for good reason - upgrade carelessly and it's gone) - hence modules are now in /sites/default/modules etc - so putting this code in /includes/ is probably not the most architecturally preferred solution, but it's simple & works. Any for me, next time I upgrade Drupal, I'll be migrating to my other hosting provider who are on the ball with providing PHP upgrades, so wont need this workaround.