# RFC: Add a deprecated modifier for functions

- Status: Obsolete
- Authors: Yussuf Khalil dev@pp3345.de
- Date: 2012-12-25
- Version: 1.0
- Original: https://wiki.php.net/rfc/deprecated-modifier
- Page: https://externals.io/rfc/deprecated-modifier
- 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

## Discussions on the mailing list

- [RFC: Add a deprecated modifier for functions](https://externals.io/message/64435.md) — started on 2012-12-26, 11 messages
- [About RFC for deprecated modifier](https://externals.io/message/72001.md) — started on 2014-02-02, 4 messages

---

> This proposal has been **superseded** by [\#\[\\Deprecated\] Attribute](https://wiki.php.net/rfc/deprecated_attribute), which has been implemented in PHP 8.4.

## Introduction

This RFC proposes the addition of a “deprecated” modifier for methods and functions giving the ZEND\_ACC\_DEPRECATED flag to functions, thus throwing an E\_DEPRECATED error when they are called.

## How can this be useful?

It is common for large PHP frameworks to deprecate old functions and methods that are still in use (by plugins for example) when releasing new versions. Later, these functions will usually be completely removed. Native functions only need the ZEND\_ACC\_DEPRECATED flag and Zend will automatically throw an E\_DEPRECATED error when they are called. However, a userspace function can only be deprecated by either adding the @deprecated tags to the doc comment or by throwing an E\_USER\_DEPRECATED error. Why does a userspace developer need to throw an error himself while a native function only needs a flag?

Simply deprecating a function by adding a deprecated modifier to the function declaration is cleaner, faster and more obvious for developers when looking at the function declaration.

Custom E\_USER\_DEPRECATED errors could rather be used for deprecating whole libraries or specific ways of calling a function.

Also, ReflectionFunction::isDeprecated() is currently useless for userspace functions which would be changed by adding this modifier.

## Examples

```php
deprecated function myFunction() {
    // ...
}
 
myFunction();
```

```
Deprecated: Function myFunction() is deprecated in ... on line 5
```

```php
class MyClass {
    public deprecated static function myMethod() {
        // ...
    }
}
 
MyClass::myMethod();
```

```
Deprecated: Function MyClass::myMethod() is deprecated in ... on line 7
```

## Patch

A pull request is available at <https://github.com/php/php-src/pull/244>.

This patch adds a T\_DEPRECATED token and sets the ZEND\_ACC\_DEPRECATED flag for every function declaration preceded by this token. It properly checks for multiple deprecated modifiers or deprecated properties and throws an E\_COMPILE\_ERROR in these cases.

## Changelog

1. 2012-12-25 RFC created and published
