Home  >  Article  >  Backend Development  >  php 如何设置已经过期(废弃)的函数

php 如何设置已经过期(废弃)的函数

WBOY
WBOYOriginal
2016-06-06 20:38:011629browse

我之前的系统框架,CONTROLLER层自定义了一个载入指定MODEL的实例方法。

现在想使用 Composer autoload,想把之前载入MODEL的实例方法废弃,但是如果直接关闭这个方法,涉及到的代码比较多,我想先把方法改为已过期,在开发时产生有警告,但是程序不会出错。

回复内容:

我之前的系统框架,CONTROLLER层自定义了一个载入指定MODEL的实例方法。

现在想使用 Composer autoload,想把之前载入MODEL的实例方法废弃,但是如果直接关闭这个方法,涉及到的代码比较多,我想先把方法改为已过期,在开发时产生有警告,但是程序不会出错。

<code>/**
 * @deprecated
 */
function foobar() {
    if (DEBUG) { // DEBUG是自行定义的调试开关常量
        trigger_error('foobar() is deprecated!');
    }

    // code
}
</code>

phpdoc有对应的标签

<code>/**
 * @deprecated
 */
</code>

http://phpdoc.org/docs/latest/references/phpdoc/tags/deprecated.html

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn