Lets say I have a method:
public function createFoo(Foo $foo, $isPremiumFoo=false);
事后看来,让
$isPremiumFoo
标志参数挂在方法末尾有点儿傻。因此我们把它放到了 Foo
中,现在我想从方法签名中删除它。但我不想一下子全部删除,因为这是一个公共方法,已经被外部使用。我想使用 @deprecate
警告用户停止使用它,然后最终将其移除。由于 PHP 中不能重载方法,那么怎样才能只弃用该方法的参数而不是整个方法呢?
createFoo
的内容,只需在其前面添加func_num_args
检查即可(我假设您正在谈论弃用createFoo($foo, true)
和createFoo($foo, false)
调用;否则,仅检查$isPremiumFoo === false
将是微不足道的)。 - raina77ow@deprecated
而不将整个方法标记为过时。 - Josh Johnson