PHPackages                             danielescherzer/define-deprecated - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. danielescherzer/define-deprecated

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

danielescherzer/define-deprecated
=================================

Allow defining deprecated global constants at runtime without dropping PHP &lt;8.5 support

v1.0.0(3mo ago)11MITPHPPHP ^8.1CI passing

Since Apr 10Pushed 3mo agoCompare

[ Source](https://github.com/DanielEScherzer/define-deprecated)[ Packagist](https://packagist.org/packages/danielescherzer/define-deprecated)[ RSS](/packages/danielescherzer-define-deprecated/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Define Deprecated
=================

[](#define-deprecated)

About
-----

[](#about)

This composer library implements a way to define constants at runtime that should be marked as deprecated. On PHP 8.4 and below, the constant is defined using [`define()`](https://www.php.net/manual/en/function.define.php), while on PHP 8.5 and above, the constant is defined using [`eval()`](https://www.php.net/manual/en/function.eval.php) with the [`#[\Deprecated]` attribute](https://www.php.net/manual/en/class.deprecated.php) applied.

For background, see [this blog post](https://scherzer.dev/Blog/20250429-attributes-on-constants#content-using) - other than `eval()` there is no easy way to make use of the ability to deprecate constants on PHP 8.5 without also requiring PHP 8.5 as the minimum supported version of the code.

Installation
------------

[](#installation)

The library is meant to be installed via composer, e.g. using `composer require danielescherzer/define-deprecated`.

It supports (and is tested against) PHP 8.1 and later.

Usage
-----

[](#usage)

The primary entrypoint of this library is the function `\DanielEScherzer\DefineDeprecated\define_deprecated()` which accepts a name, value, deprecation message, and deprecation version. It wraps around the `\DanielEScherzer\DefineDeprecated\ConstantDefiner` class which holds the actual logic; since PHP does not yet support function autoloading, the `define_deprecated()` function is always loaded.

To use it:

```
