Function overloading workaround
Posted: Mon Feb 21, 2011 10:58 am
Hi there.
I have a function Create(). It's a single function with no formal arguments declared.
Here, how it's supposed to be used:
I need all this calling variants into a one function. Which variant called is decided by the $Type argument.
First, I'm getting list of the arguments.
So here comes the hard part: since there can be any amount of arguments because of default null value, I can't just set variables with value of $Arguments[$I]. Going with many if() statements, checking if $Arguments[$I] exists, is quite bad way.
How would you solve that problem? I have a couple of ideas with using arrays, but I want to hear your opinion.
P.S. No native support of overloading and no readonly properties makes me angry.
I have a function Create(). It's a single function with no formal arguments declared.
Here, how it's supposed to be used:
Code: Select all
function Create($Type = null, $Title = null, $Icon = null, $URL = null, $Target = null, $Sort = null, $Active = null);
function Create($Type = null, $Title = null, $Icon = null, $Sort = null, $Active = null);
function Create($Type = null, $Sort = null, $Active = null);
First, I'm getting list of the arguments.
Code: Select all
$Arguments = func_get_args();
if(count($Arguments) > 0)
{
switch($Arguments[0])
{How would you solve that problem? I have a couple of ideas with using arrays, but I want to hear your opinion.
P.S. No native support of overloading and no readonly properties makes me angry.