answersLogoWhite

0


Best Answer

You cannot overload PHP functions. Function signatures are based only on their names and do not include argument lists, so you cannot have two functions with the same name. Class method overloading is different in PHP than in many other languages. PHP uses the same word but it describes a different pattern.


You can, however, declare a variadic function that takes in a variable number of arguments. You would use func_num_args() and func_get_arg() to get the arguments passed, and use them normally.


For example:


// *******************************************

function myFunc() {

for ($i = 0; $i < func_num_args(); $i++) {

printf("Argument %d: %s\n", $i, func_get_arg($i));

}

}


/*

Argument 0: a

Argument 1: 2

Argument 2: 3.5

*/

myFunc('a', 2, 3.5);

// ********************************************

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Are the php functions overloading allowed?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is constructor overloading allowed in PHP?

Yes. It can be done like so: class myClass{ var $foo; function __construct($bar){ $this-&gt;foo = $bar; } }


define function overloading?

Defining several functions with the same name with unique list of parameters is called as function overloading.


How the compiler compiles overloaded method?

method overloading occurs when we use two functions or more with the same name.In function overloading compiler detect which method is call actually throw the parameters passed to the methods.In function overloading parameters of functions are different.


What are the functions of PHP?

http://www.php.net/quickref.php


How many in-built functions in PHP?

There are thousands.


How are PHP and MySQL compatible?

By sending messages to the MySQL server, you can communicate with the database. To submit SQL queries to the database, you use PHP functions. You don't need to know how to communicate with MySQL because PHP takes care of that. You only need to be familiar with SQL queries and PHP functions. To learn more about data science please visit- Learnbay.co


What are all the built-in PHP functions?

See the related links for a shortcut to the entire reference of every function in PHP. The default built-in functions differ from the categories of extensions you choose to install, and the version of PHP you're installing - therefore, it's impossible to give a stable list of built-in functions.


What are the advantages and disadvantages of the PHP functions include and require and any functions that branch off of them?

something


Where could one find a manual for the PHP mail functions?

One can find a manual for the PHP mail functions on the PHP Mail website. One can read it online or print it out to read as a hard copy. The manual is also available on the 'NuSphere' website.


Are all the PHP 6 functions and codes supported by WAMP 2.0i?

PHP 6 hasn't been released yet.


What is PHP data coding?

PHP data coding is softwares that allows or has frameworks which can make PHP input to it's own script language. So you may code programs for example with PHP, just that it has to be extended PHP because of new functions and features. It may also be application coding for the web.


How do you use regular expressions in PHP?

Use the preg functions (ereg functions are deprecated) Wiki regex to form your regex string