this post was submitted on 23 Jun 2025
4 points (75.0% liked)

Programming

23 readers
1 users here now

My various programming endeavours, mainly in PHP (Symfony), Typescript (Angular), Go and C#. With a sprinkle of Java and C++ here and there.

founded 5 months ago
MODERATORS
 

This change is quite straightforward, so this won’t be a long article. PHP 8.5 adds support for annotating non-class, compile-time constants with attributes. Compile-time constants are those defined using the const keyword, not the define() function.

Attributes can now include Attribute::TARGET_CONSTANT among their valid targets. Additionally, as the name suggests, Attribute::TARGET_ALL now includes constants as well. The ReflectionConstant class has been updated with a new method, getAttributes(), to support retrieving these annotations.

One particularly useful aspect of this change is that the built-in #[Deprecated] attribute can now be applied to compile-time constants.

As promised, this was a short post, since the change is relatively simple. See you next time—hopefully with a more exciting new feature in PHP 8.5!

top 1 comments
sorted by: hot top controversial new old
[–] chrastecky@phpc.social 1 points 2 weeks ago