At the team with which I work we have lots of own old deprecated PHP functions that are used through out the project. We can rewrite old code to use new API but it requires a lot of time and effort and it doesn't fit in our current priorities. The best we can do now is to mark such functions as deprecated to prevent developers to use them in new code.
PHP 5.3.0 introduced two new error levels: E_DEPRECATED and E_USER_DEPRECATED. The E_DEPRECATED error level is used to indicate that a function or feature has been deprecated. The E_USER_DEPRECATED level is intended for indicating deprecated features in user code, similarly to the E_USER_ERROR and E_USER_WARNING levels.
So, generally speaking adding the code like this to the deprecated function definition will do the job:
trigger_error('Deprecated function user!', E_USER_DEPRECATED);
I have introduced the wrapper function that will show warning similar when deprecated core PHP functions like ereg are used:
/** * Special function to mark functions as deprecated. Put the call * to it onto the top of function declaration you want to deprecate. */ function deprecated() { // Get name of function that called deprecated() function. $function = $stack[1]['function']; E_USER_DEPRECATED); }
You may just add the call to deprecated() function at the top of your deprecated function. Like this:
/** * Perform database query. * @deprecated */ function doques_db_query() { deprecated(); $args = func_get_args(); return call_user_func_array('mysqli_query', $args); }

Comments
Post new comment