在 PHP 类中,我有一个成员计数器:
private $counter = [];
我想获取此数组的长度并将其作为方法参数的默认值传递:
public function myMethod($n = $counter)){
}
我努力了:
public function myMethod($n = count($this->$counter))){
// not working
}
public function myMethod($n = count($this->counter))){
// not working
}
public function myMethod($n = array('MyClass', count($counter)))){
// still not working
}
public function myMethod($n = $this->methodReturningCounterLength()){
// not working
}
甚至有可能我正在尝试做的事情吗?
红糖糍粑
潇潇雨雨
蝴蝶不菲