简体   繁体   中英

How can we do overloading in php?

在Java中,当我们定义两个带有不同数量参数的方法时,我们称其为重载。我们如何在php或javascript中做到这一点,其中传递的参数数量不必等于定义的参数。

Javascript:

function testing(){
     console.log(arguments);//<-- all func args
}

PHP:

function testing(){
    var_dump(func_get_args());//<-- all func args
}

You can assign default values to the parameters like so:

function example(a = 1, b = 2, c = 3) {
  //Do something
}

example(10, 5);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM