Read the latest web development and design tips at Fred Wu's new blog! :-)
Poke me on GitHub

Archive for the ‘Testing’ Category

json_encode() for PHP4 and early PHP5

Had a beauty today. There I was ready to deploy some nicely polished code to the server. After some thorough local testing it looked like it’d be a smooth process. So the code went up, but all my funky AJAX stuff stopped working on the server. How could that be? It was perfect locally… :)

It took a little while but in the end I realised what was going on – json_encode wasn’t working. The server was running PHP 5.1.6 and json_encode only became “standard” with PHP 5.2.0 onward.

I needed a solution fast. No time to recompile a newer version of PHP, add libraries or anything fancy like that. I just needed the function json_encode to work right now. Thankfully, the solution was as easy as adding replacement a function a user kindly submitted from the PHP site itself:

http://au.php.net/manual/en/function.json-encode.php#82904

I blindly assumed PHP 5 was PHP 5. I wasn’t using any extremely fancy commands or anything, but I still came unstuck. So the moral of today is check your server specification right down to every last decimal point! ;)

Related posts