互换的青春
使用不同的参数集定义相同的函数名两次(或更多)时,会发生函数重载。例如:class Addition { function compute($first, $second) { return $first+$second; } function compute($first, $second, $third) { return $first+$second+$third; }}在上面的示例中,函数compute使用两个不同的参数签名重载。* PHP尚不支持此功能。另一种方法是使用可选参数:class Addition { function compute($first, $second, $third = 0) { return $first+$second+$third; }}扩展类并重写父类中存在的函数时,会发生函数重写:class Substraction extends Addition { function compute($first, $second, $third = 0) { return $first-$second-$third; }}例如,compute覆盖中所述的行为Addition