以下是此主题:How to handle functions deprecation in library?我想找到一种方法来跟踪对已弃用函数的所有调用,以便我可以确保在函数被删除之前全部替换它们。鉴于以下PHP方法跟踪使用标记为弃用的函数
/*
@deprecated - just use getBar()
*/
function getFoo(){
return getBar();
}
function getBar(){
return "bar";
}
我想出了以下方法这样做,我正在寻找反馈。
function getFoo(){
try{
throw new Exception("Deprecated function used");
} catch(Exception $e){
//Log the Exception with stack trace
....
// return value as normal
return getBar();
}
}
传播在E_STRICT运行的福音+1 :) – 2010-01-06 16:57:35
戈登,我喜欢你的解决方案,因为它让我觉得我不会滥用例外。我看到的一个缺点是,它并没有为程序员提供有问题的调用,就像堆栈跟踪一样,但只是调用已经完成。 – Scott 2010-01-06 18:08:28
Scott:随意添加任何魔术常量来调整错误消息,只要您认为合适:http://us.php.net/manual/en/language.constants.predefined.php或包含来自'debug_backtrace( )' - 上面的例子是为了可读性故意缩短的。 – Gordon 2010-01-06 18:17:21