【发布时间】:2018-02-11 13:24:54
【问题描述】:
<?php
class klasa {
public function funkcja($x = 'default', $y = 'value')
{
var_dump($x);
var_dump($y);
}
}
$x = new klasa;
$x->funkcja('other value');
如图所示,如何省略第一个参数有他的默认值,只影响第二个?
我试过$x->funkcja(NULL, 'other value');不行,$x->funkcja(, 'other value');也不行。
如何实现?
【问题讨论】:
-
来自PHP Documentation
Note that when using default arguments, any defaults should be on the right side of any non-default arguments; otherwise, things will not work as expected... 如果您绝对必须这样做,请考虑传递一个包含关联数组的参数;但是您必须处理功能代码中的差异
标签: php function methods parameters