diff --git a/sitemap.xml b/sitemap.xml
index 4ee0b14..48e1e6a 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -81,4 +81,7 @@
https://scherzer.dev/Blog/20260309-php-friends
+
+ https://scherzer.dev/Blog/20260410-define-deprecated
+
diff --git a/src/Blog/posts/20260410-define-deprecated.md b/src/Blog/posts/20260410-define-deprecated.md
new file mode 100644
index 0000000..fc9ccfd
--- /dev/null
+++ b/src/Blog/posts/20260410-define-deprecated.md
@@ -0,0 +1,109 @@
+---
+extensions:
+ pygments: true
+title: Introducing define_deprecated() for PHP
+---
+
+# Introducing define_deprecated() for PHP
+
+In PHP 8.5, I introduced support for [attributes on constants][blog-attribs],
+which allows marking compile-time global constants as deprecated. However,
+that functionality was not made easily available when defining constants at
+*runtime*, or in code that supports older versions of PHP. My new library,
+[danielescherzer/define-deprecated][lib-def-dep], provides that support.
+
+## Overview
+
+PHP 8.5's support for attributes on constants introduced new syntax that older
+versions of PHP cannot parse. This creates a problem for libraries that want to
+support multiple versions of PHP: even *declaring* a constant with attributes
+will cause a parser error on older versions of PHP. The solution is to wrap the
+constant declaration in [`eval()`][docs-eval], which ensures that the code is
+parsed at runtime, making it possible to conditionally execute it on PHP 8.5+.
+
+While `eval()` is often avoided, here it provides a controlled way to
+conditionally use syntax that older versions of PHP are unable to understand.
+Exhaustive tests, and the use of [`var_export()`][docs-var-export], confirm that
+`eval()` does not present an opportunity for executing arbitrary code, even when
+passing untrusted inputs to the library. That said, on PHP 8.4, as attributes
+are unavailable, `eval()` is unnecessary; the declaration of constants can be
+delegated to the existing function for creating new constants at runtime:
+[`define()`][docs-define]. `eval()` is only required for, and used on, PHP 8.5+.
+
+My new library exposes a new global function, `define_deprecated()`, in the
+`\DanielEScherzer\DefineDeprecated` namespace with the following signature:
+
+```php startinline=True
+function define_deprecated(
+ string $constant_name,
+ mixed $value,
+ ?string $message,
+ ?string $since
+): bool {
+ // ...
+}
+```
+
+The first two parameters, `$constant_name` and `$value`, correspond to the
+parameters for the `define()` function, or to the constant name and value used
+in compile-time declarations. The remaining two parameters, `$message` and
+`$since`, correspond to the parameters of the
+[`#[\Deprecated]`][docs-deprecated] attribute - the message explaining why the
+constant is deprecated, and the version in which the constant was deprecated.
+
+While the `#[\Deprecated]` attribute does allow the `$message` and `$since` to
+be omitted (defaulting to `null`), this function requires them to be explicitly
+passed (even if `null`) to encourage documenting deprecations.
+
+## Example
+
+To make use of the new library, install the package via composer, for example:
+
+```bash
+composer require danielescherzer/define-deprecated
+```
+
+After installing the package, you can define a deprecated constant like this:
+
+```php
+ 'https://packagist.org/packages/danielescherzer/commonmark-ext-pygments-highlighter',
'desc' => 'CommonMark extension for code highlighting with Pygments',
],
+ 'define-deprecated' => [
+ 'name' => 'danielescherzer/define-deprecated',
+ 'link' => 'https://packagist.org/packages/danielescherzer/define-deprecated',
+ 'desc' => 'Allow defining deprecated global constants at runtime without dropping PHP <8.5 support',
+ ],
'html-builder' => [
'name' => 'danielescherzer/html-builder',
'link' => 'https://packagist.org/packages/danielescherzer/html-builder',
@@ -345,7 +350,7 @@ private function addPackagesSection(): void {
'p',
[],
<<magna cum laude in 2024 with a Bachelor of Science degree. As part of my work in Computer
Science, I chose to write an honors thesis in my senior year, see here for details. I continued at Tufts for graduate school, graduating in 2025 with
a Master of Science in Computer Science degree.
See the links in the navigation bar above for more information about my
-experience.
- LinkedIn
- Email:
daniel.e.scherzer@gmail.com
I also have a blog. You can see a full index of my posts here. My latest blog post is:
Friends in PHP
Monday, 09 March 2026As I mentioned in my last blog post, while at ConFoo I and a few
-other developers worked on some ideas for adding friendship support to PHP. To
-be clear, these are just ideas at the moment, but I figured they were worth
-sharing. Continue reading...