Archive for August 13th, 2007

Frustrating PHP 4 Objects

Today I tried the following:

function getObject()
{
$object = new Object();
return $object;
}
getObject()->executeMethod();

Well the code above works perfectly …
All great, the app worked, so I’ve committed the project to Subversion.
Upload it to our production server..

Crash!
Well the production server runs PHP4.
Our development server runs PHP5.

In PHP4, You first must put the result of the method call in a variable…

$obj = getObject();
$obj->executeMethod();

*sigh* Sometimes I hate PHP!

Great method to_json

A very nice method to convert a Ruby array to Javascript.

print { ‘key1′ =>  ‘value1′, ‘key2′ => [ 12, 3 ] }.to_json
outputs:  { key1: ‘value1′, key1: [ 1, 2, 3 ] }