我正在寻找一种在类的所有实例上调用函数的方法,最好是通过静态方法调用。
例子:
class number{
private $number;
static function addAll(){
//add all of the values from each instance together
}
function __construct($number){
$this->number = $number;
}
}
$one = new number(1);
$five = new number(5);
//Expecting $sum to be 6
$sum = number::addAll();
对此的任何帮助将不胜感激。谢谢!