【发布时间】:2017-02-15 13:52:25
【问题描述】:
我需要构建一个方法column,它可以用不同的参数类型调用,比如这里的情况。
->column('herald','style')
->column('herald','style','styleText')
->column('herald',['kind','style'])
->column('herald',['kind','style'],['kindText','styleText'])
->column('item',['kind','style'],false)
->column('item',['kind','style'],['kindText','styleText'],false)
->column('herald_style','style',false)
->column('herald_style','style','styleText',false)
我只是希望函数可以被清楚地调用,像Java那样覆盖,我已经尝试使用func_get_args()来处理参数,但它似乎更糟糕..
那有什么办法吗?
【问题讨论】:
-
您可以在函数参数中指定一个默认值,例如 function coloumn($a=null,&b=null,$c=null,$d=null){}
-
你说的参数是什么意思 - ['kind','style']?
-
我认为他希望参数可能是一个数组。@SanjayKumarNS
-
@Pradyut Manna 是的,我也这么认为。
-
@Fan,你能详细解释一下你想做什么吗?这种方法似乎不是最好的方法。
column()做什么?
标签: php function laravel arguments