Joomla – How printing $app object in index.php display the whole site contents
Joomla is the most wanted CMS application I have ever seen. Currently I am using Joomla 1.6. If you notice the index.php located at the root of joomla installation, you can see an object $app playing an important role in making the site contents. $app is an object of the class Jsite, class Jsite is defined in /includes/application.php. The class Jsite is extended from the class JApplication which is defined in libraries/joomla/application/application.php. Object $app calling several methods and finally print out the entire contents by the code echo $app; Its understood that an object cant print out any contents just by an echo statement. then how the code echo $app prints out the entire site contents ? here is the magic of the magic method __toString().
The __toString() method allows a class to decide how it will react when it is treated like a string.This method must return a string.
The method __toString() is defined in the class Japplication. (class Jsite is a subclass of Japplication) so when code echo $app execute it calls the method __toString() defined in the class Japplication which in turn return the site contents.