Analogous to docblock annotations, attributes make it possible to apply metadata to a class, function, or property with a native syntax and reflection API. The original <<Attr>>
syntax accepted for PHP 8.0 had several shortcomings which were addressed by changing the syntax to @@Attr
. Now there is a new proposal to borrow Rust’s #[Attr]
syntax instead. In this post I examine the main arguments for this change and why I still believe the @@
syntax is best.
Tag: PHP
PolyCast: a library for safe type conversion in PHP
On March 16, 2015, something amazing happened in the world of PHP. The long-awaited, hotly debated Scalar Type Declarations RFC was accepted for PHP 7! Finally, it will be possible to declare scalar types (int, float, bool, and string) for function parameters and return values: The need for safe type casts By default, scalar types… Continue reading PolyCast: a library for safe type conversion in PHP
Implementing a linked list in SQL
Recently I was challenged with enabling users to drag and drop items in a list to sort them in any order, and persisting that order in a SQL database. One way to handle this would be to add an index column to the table, which could be updated when an item is reordered. The downside… Continue reading Implementing a linked list in SQL
Responsive Captcha: A small PHP library for preventing spam
If you’re reading this, you probably already know what a CAPTCHA is. The most common form consists of an image with warped or obscured characters which must be entered into a text field. While these image-based CAPTCHAs tend to be effective at stopping spam, they are also poorly accessible, often slow, and require a third-party… Continue reading Responsive Captcha: A small PHP library for preventing spam