PHP Funny Behaviour

Today I found a small example of a php code that reminded me the endless battles between ruby/python and php folks stating how bad the php is. Well… let’s see the small example:

<?php
$ee = new e();
$ee->x();

print_r($ee);

class e
{
  function x()
  {
    print "run x()\n";
  }
}

running this returned no error, but instead the output is like this:

run x()
e Object
(
)

Yea… it seems that’s quite normal in the PHP world to instantiate an object of a class that is going to be declared later. And what’s more, the object is quite good :) wonderful.