开发者

How can we do overloading in php?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜