Don’t define json_encode with Zend_Json

Some web servers are still working with PHP5.1.6. That means json_encode/json_decode is not supported by default. Although some libraries are using json_encode, for instance php-sdk for facebook, so I defined json_encode like this:

function json_encode($data)
  return Zend_Json::encode($data);

I didn’t know that actually Zend_Json uses json_encode in their code, so badly it will be an infinite loop. In PHP5.1.6, this code raises a segmentation fault:

function a()
  return a();

It’s a bit difficult to recognize what’s wrong. In PHP5.3 with memory_limit, it will return a memory size error.

This entry was posted in Tweak and tagged . Bookmark the permalink. Both comments and trackbacks are currently closed.