开发者

How can we do overloading in php?

开发者 https://www.devze.com 2023-03-31 17:39 出处:网络
In java we call it overloading when we define two methods with different numbers of arguments.How do we do it in php or javascript开发者_开发问答 where number of parameters passed need not be equal to

In java we call it overloading when we define two methods with different numbers of arguments.How do we do it in php or javascript开发者_开发问答 where number of parameters passed need not be equal to arguments defined.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消