tags:

views:

79

answers:

2

Is function overloading possible in php.If yes, then how and if not then why?

Thanks in advance.

I have checked the php manual which gives solution to overloading as mail() function can be overloaded by mb_mail() function .

But is this the proper way for overloading

+1  A: 

This can only be done internally (through a PHP extension), unless you install the PECL runkit extension, which exposes function overloading functionality to userspace.

However, you probably don't want to use runkit in a production environment, so there's no good way to do this from userspace.

Artefacto
In your opinion, how to implement function overloading
Ankur Mukherjee
@Ankur Why do you need it for? Can't you just wrap the function in another one?
Artefacto
@Ankur did you read his answer?
Pekka
yes sir i read it
Ankur Mukherjee
+3  A: 

No. Because it has not been implemented. There's a PECL extension that allows you to do this, but it makes your code not portable to environments where this extension is not available.

Don't ask why it has not been implemented.

Since PHP 5.3 you can use namespaces for 'kind of' overloading

namespace MyNamespace;

function mail() {
   return \mail();
}
Mchl