readonly + Constructor Promotion: DTOs in Five Lines
The 40-line value object - properties, constructor assignments, getters - collapses into a declaration. Modern PHP makes immutable data carriers nearly free to write.
Software Engineer
I build web applications and share what I learn along the way.
Step-by-step programming tutorials on PHP, JavaScript, Laravel, WordPress and more.
The 40-line value object - properties, constructor assignments, getters - collapses into a declaration. Modern PHP makes immutable data carriers nearly free to write.
Order statuses as loose strings invite typos, scattered labels and unguarded transitions. PHP 8.1 enums centralize the values, their behavior, and - with match - force you to handle every case.
?->, ??=, throw as an expression, and the spaceship - four small operators from recent PHP that collectively delete the noisiest guard code in legacy files.
PHP 8.1 turned functions into values you can pass, store and compose - ending the string-callable era of 'array_map("strtoupper", ...)' and its silent refactoring bugs.
Titles, prices and buttons at different heights across cards - the misalignment that made designers invent equal-height hacks - is what subgrid was built to end.
Every chat box and comment field ships JS that measures scrollHeight to grow the textarea. One CSS property now does it natively - with a progressive-enhancement story for the rest.
Half your dark-mode CSS is pairs of rules flipping the same property. light-dark() collapses each pair into one line - and color-scheme unlocks free dark UI from the browser itself.
Order confirmations, tickets, recipes, documentation - they get printed and PDF-saved daily. Twenty lines of @media print separates professional from embarrassing.
When a dropdown hides behind a header despite a huge z-index, the number is not the problem - the element is trapped in a stacking context. Here is the mental model and the debugging routine.
Elements appearing via display changes always snapped into place because there was no "before" state to transition from. Two new pieces of CSS fix entry AND exit animations.
animation-timeline: scroll() binds any CSS animation to scroll position - reading progress bars, parallax, scroll reveals - running off the main thread entirely.
Notification badges showing "0", alert boxes rendering as empty bordered rectangles, list wrappers with padding and no list - :empty cleans up after your templates.