# Deprecated functions

- Thread: https://externals.io/message/77128
- Original archive: https://news-web.php.net/php.internals/77128
- Started by Tjerk Meesters on 2014-09-10T05:42:38+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #77128 — Tjerk Meesters — 2014-09-10T05:42:38+00:00

URL: https://externals.io/message/77128#77128

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?

---

## #77129 — Levi Morrison — 2014-09-10T05:57:05+00:00

URL: https://externals.io/message/77128#77129 · In reply to: #77128

On Tue, Sep 9, 2014 at 11:42 PM, Tjerk Meesters
<tjerk.meesters@gmail.com> 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?

This sounds like a much better solution than what we have. The only
way the test could be less brittle is if you could define a function
and deprecate it in userland as part of the test. Since we don't have
that capability and don't think we should add it I say +1.

---

## #77130 — Alexander Lisachenko — 2014-09-10T05:59:07+00:00

URL: https://externals.io/message/77128#77130 · In reply to: #77128

Hi!

Maybe it will be better to do this in another way: introduce an RFC to
add 'deprecated' keyword into the syntax like 'final' or 'protected'.
There are many frameworks that want to deprecate some methods or
classes. Currently it's only possible via "@deprecated" tag in the
phpDoc-block, but this tag doesn't influence on method invocation, so
no warnings are generated.

Symfony uses trigger_error($message, E_USER_DEPRECATED) explicitly in
deprecated methods to trigger this warning (see
https://github.com/symfony/symfony/pull/6180), but this is not a
transparent solution.

This can be look like this:

class Test {
    deprecated protected $someProperty;

    deprecated public function foo() {}
    public function bar() {}
}


deprecated class OldStuff {}

deprecated function someOldFunction() {}

This RFC will give more control over 'deprecated' functionality and
can be easily tested.

Thoughts?

2014-09-10 9:42 GMT+04:00 Tjerk Meesters <tjerk.meesters@gmail.com>:
> 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?

---

## #77131 — Tjerk Meesters — 2014-09-10T07:14:01+00:00

URL: https://externals.io/message/77128#77131 · In reply to: #77130

Hi Alex,



> Hi!
> 
> Maybe it will be better to do this in another way: introduce an RFC to
> add 'deprecated' keyword into the syntax like 'final' or 'protected'.
> There are many frameworks that want to deprecate some methods or
> classes. Currently it's only possible via "@deprecated" tag in the
> phpDoc-block, but this tag doesn't influence on method invocation, so
> no warnings are generated.

Any decent IDE should tell you that a function is deprecated by observing DocBlock; I believe PhpStorm uses strike-through to indicate deprecated functionality.

> 
> Symfony uses trigger_error($message, E_USER_DEPRECATED) explicitly in
> deprecated methods to trigger this warning (see
> https://github.com/symfony/symfony/pull/6180), but this is not a
> transparent solution.

I agree that having a ‘deprecated’ keyword would simplify matters, but I don’t think that alone is worth making it a language feature.

This could be a good case for annotations, though, if we ever get such a thing :)

> 
> This can be look like this:
> 
> class Test {
>    deprecated protected $someProperty;
> 
>    deprecated public function foo() {}
>    public function bar() {}
> }
> 
> 
> deprecated class OldStuff {}
> 
> deprecated function someOldFunction() {}
> 
> This RFC will give more control over 'deprecated' functionality and
> can be easily tested.
> 
> Thoughts?
> 
> 2014-09-10 9:42 GMT+04:00 Tjerk Meesters <tjerk.meesters@gmail.com>:
> > […]

---

## #77133 — Matteo Beccati — 2014-09-10T07:49:50+00:00

URL: https://externals.io/message/77128#77133 · In reply to: #77128

> void __deprecated__() { }
> 
> And mark that function as eternally deprecated using the ZEND_ACC_DEPRECATED flag.

Is it really worth adding a new completely useless function just for a
test? It's not like functions are actually removed every day...


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/

---

## #77134 — Chris Wright — 2014-09-10T09:20:47+00:00

URL: https://externals.io/message/77128#77134 · In reply to: #77128

> 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.

---

## #77210 — Stas Malyshev — 2014-09-15T06:27:55+00:00

URL: https://externals.io/message/77128#77210 · In reply to: #77128

Hi!

> 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.

If this is needed only for testing, this should only be enabled with
ZEND_DEBUG flag active. Like leak() one.

-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
