Monthly Archives: September 2014

Implement a Singleton Pattern in Javascript var SingletonClass = (function(){ function SingletonClass() { //do stuff } var instance; return { getInstance: function(){ if (instance == null) { instance = new SingletonClass(); // Hide the constructor so the returned objected can’t be new’d… instance.constructor = null; … Continue reading

Posted in Javascript | Leave a comment

Overloading in PHP

Overloading has a different meaning in PHP. PHP does not support function overloading in the same manner as C++. However it possible to pass different number of arguments to a function using func_get_args. function findSum() { $sum = 0; foreach … Continue reading

Posted in PHP | Leave a comment


As of PHP 5.4.0, PHP implements a method of code reuse called Traits. Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling … Continue reading

Posted in PHP | Leave a comment

Index in MySQL

Most MySQL indexes (PRIMARY KEY, UNIQUE, INDEX, and FULLTEXT) are stored in B-trees. Exceptions are that indexes on spatial data types use R-trees, and that MEMORY tables also support hash indexes.

Posted in Database | Leave a comment

How does MySQL uses indexes ?

If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer to find rows. For example, if you have a three-column index on (col1, col2, col3), you have indexed search capabilities on … Continue reading

Posted in Database | Leave a comment

Language Comparision

Variables JS var colors = “green”; PHP $colors = “green”; ========================================== Array JS var colors ; colors = [‘white’,’black’,’brown’]; colors[0]; OR var colors = Array(‘white’,’black’,’brown’); colors.item(0); ========================================== Object JS: var hotel = { name: ‘Super8’, rooms: 40, booked: 25 checkAvailability … Continue reading

Posted in General | Leave a comment