Re: [PHP-DEV] Deprecated functions

[email protected] (Chris Wright)
Newsgroups php.internals
Message-ID <CAGAGxbYL4cF41iyMf2YvfJC6yPR-+uXaTUT3HjWE+2UB8daidg@mail.gmail.com>
On 10 September 2014 06:42, Tjerk Meesters <[email protected]> wrote:
> Hi,
>
> When I was fixing test cases on my `kill-ereg` branch I noticed a Reflection test case for `ReflectionFunction::isDeprecated()`.
>
> The problem with such a test case is that you’d be chasing deprecated functions to tests against as we move along; this is the current list of deprecated functions as taken from a typical 5.4 installation:
>
> Since 4.1.0: call_user_method, call_user_method_array
> Since 4.3.7: mysql_list_tables, mysql_listtables
> Since 5.3  : ereg, ereg_replace, eregi, eregi_replace, split, spliti, sql_regcase, mysql_db_query, magic_quotes_runtime, set_magic_quotes_runtime, set_socket_blocking
> Since 5.4  : mysql_list_dbs
>
> The above are, as far as I’m concerned, all potential candidates for removal in PHP 7, so in order to reliably test a deprecated function I would suggest introducing a hidden function with this signature:
>
> void __deprecated__() { }
>
> And mark that function as eternally deprecated using the ZEND_ACC_DEPRECATED flag.
>
> Thoughts?

An alternative could be this:

--FILE--
<?php

error_reporting(E_DEPRECATED);

foreach (get_defined_functions()['internal'] as $func) {
    $ref = new \ReflectionFunction($func);

    if ($ref->isDeprecated()) {
        $func();
        break;
    }
}

?>
--EXPECTF--

Deprecated: Function %s() is deprecated in %s on line %d


...although arguably this is testing the error rather than the
reflection function. This also assumes that there will always be at
least one deprecated function in the standard library, although I
doubt this is likely to be an issue any time soon.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.