Pages

Wednesday, January 22, 2014

Method overloading in codeigniter / php

Correct way to overload a method in codeigniter/php:


function mymethod($id = null)
{
   if (isset($id))
   {
      echo "My method with one parameter";
   }
   else
   {
      echo "My method with no parameters";
   }
}

The above method can be invoked by:


mymethod();
mymethod(true);

No comments: