$30 off During Our Annual Pro Sale. View Details »

Modern PHP Features You're Probably Not Using (...

Modern PHP Features You're Probably Not Using (But Should Be)

You’ve read the release notes. You’ve seen the blog posts. But how many of PHP’s modern features have actually made it into your day-to-day code? Sure, you’ve heard about enums. You might’ve even dabbled with match expressions or readonly properties. But chances are, you might still be writing modern PHP with a very 7.x mindset.

This talk is your invitation to ditch the boilerplate and embrace the features modern PHP has given us. We’ll walk through a set of underused gems - from union types and readonly classes, to cleaner control flow, and smarter typing.

Expect before/after code, real-world scenarios, and the occasional “wait, you can do that now?” moment. Whether you're modernising a legacy app or just looking to write less code that does more, this session will leave you with a better understanding of how these features combine to make your code safer, more expressive, and easier to maintain.

Avatar for Paul Conroy

Paul Conroy

October 30, 2025
Tweet

More Decks by Paul Conroy

Other Decks in Technology

Transcript

  1. Modern PHP Features You're Probably Not Using (But Should Be)

    Paul Conroy / @conroyp 30th October, 2025
  2. From Dublin, Ireland Started playing with the web 30+ years

    ago (Notepad, Frontpage & Geocities!) CTO at Square1 conroyp.com / @conroyp Paul Conroy 👴 🌍 🇮🇪
  3. We’re All Busy, and Habits Run Deep • Most developers

    learn a few ways to do things early in their careers, and stick with them. • We’re focused on shipping, fixing bugs, hitting deadlines. • It’s easier (sometimes safer!) to copy a familiar pattern from elsewhere in the codebase. • That consistency is good, but it can also keep us from taking advantage of new language features.
  4. What Exactly Is an Enum? Enum == “Enumerated Type” A

    special kind of class that: • Defines a fixed set of possible values. • Gives each value a name and (optionally) data. • Lets you compare, validate, and extend safely. • A type understood by PHP!
  5. • Move the logic closer to what it represents. •

    Single place to check role-related logic.
  6. Enums: Cementing the Foundation • Replace fragile strings with structured,

    type-safe values. • Keep logic where it belongs - in the enum itself. • Validate input once, use confidently everywhere. • Generate labels and actions consistently. • Fewer bugs, less boilerplate, clearer intent.
  7. ?? ⁇ • Function starts out obvious.
 • Params added

    over time - flags!
 • Readability isn’t great.
  8. ?? ⁇ • Function starts out obvious.
 • Params added

    over time - flags!
 • Readability isn’t great.
  9. Named Arguments • Makes the code obvious.
 • Refactor-safe.
 •

    Impossible to misorder.
 • Suitable for long parameter lists.
  10. ❌ Easy to accidentally mutate after instantiation ❌ No enforcement

    of immutability ❌ Bugs creep in when state is shared across layers
  11. Readonly properties • Properties are initialised once, in the constructor.

    • Whole class can be readonly.
 • No reassignment allowed - even from inside the class.
 • 🚨🚨 Objects within readonly properties can still be mutated 🚨🚨 
 (unless they are also immutable!)
  12. Readonly properties • Properties are initialised once, in the constructor.

    • Whole class can be readonly.
 • No reassignment allowed - even from inside the class.
 • 🚨🚨 Objects within readonly properties can still be mutated 🚨🚨 
 (unless they are also immutable!)
  13. Strong & Stable Core • Data that behaves itself -

    predictable and self-describing. • Less duplication, fewer side effects. • Strong typing from start to finish. • Boilerplate replaced by intention. • Safer, cleaner, faster to read.
  14. Match Expression • Closer to if/else functionality • No fallthrough

    • Strict comparisons (===) • Must return a value!
  15. (De)faulty switch • default is easy to miss. • Silent

    failure in switch case. • Very loud failure with match!
  16. Union Types • Comment isn’t a contract! • Pass in

    precise types. • Not relying on docblocks.
  17. Intersection Types “I don’t care what type is, but it

    needs to be able to do X and Y” Make function signatures honest about what you depend on!
  18. Framing the Structure • Replace fragile switch statements with clear,

    expressive match. • Build precision into contracts with union and intersection types. • Eliminate ambiguity - make every branch and type explicit. • Let PHP’s type system catch structural errors early
  19. Property Hooks • Define get and set behavior inline with

    the property itself
 • Removes need for verbose getters/setters
 • Keeps logic close to where it’s used • Like computed properties in Swift/C#
  20. Symfony Polyfills https://github.com/symfony/polyfill • Brings newer PHP functions and classes

    to older versions. • Seamless drop-in: no code changes needed in most cases. • A lifesaver when your prod still says “7.4”!
  21. Making It A Home • #[Override] turns quiet mistakes into

    loud ones. • New array helpers and pipelines make transformations flow naturally. • Property hooks remove boilerplate from everyday code. • Polyfills let you bring modern PHP to older runtimes. • Small upgrades, big quality-of-life wins for real projects!
  22. Build With Better Materials • Clearer intent • Safer defaults

    • Expressive data • Predictable behaviour
  23. Build With Better Materials • Clearer intent • Safer defaults

    • Expressive data • Predictable behaviour
  24. Build With Better Materials • Clearer intent • Safer defaults

    • Expressive data • Predictable behaviour
  25. Small Changes, Big Wins Feature PHP Version Why It Matters

    Action Enums 8.1 Replace string constants with real, type-safe values Use for statuses, roles, categories Readonly Properties / Classes 8.2 Make data immutable & predictable Use for DTOs and value objects Promoted Constructor Props 8.0 Remove repetitive property assignments Simplify data objects and models Named Arguments 8.0 Clearer, refactor-safe calls Use for constructors & config- heavy APIs
  26. Small Changes, Big Wins Feature PHP Version Why It Matters

    Action Union & Intersection Types 8.0 / 8.1 Replace PHPDoc guesses with true contracts Declare what’s really allowed Match Expressions 8.0 Eliminate fall-through & loose checks Replace switch statements Property Hooks (+ Interfaces) 8.4 Co-locate get/set logic with data contracts Replace verbose accessors #[Override] Attribute 8.3 / 8.5 Turns silent override bugs into compile-time errors Add to subclass methods
  27. Small Changes, Big Wins Feature PHP Version Why It Matters

    Action Pipe Operator (>) 8.5 Read transformations left to right Streamline code appearance Array Helpers 8.4 / 8.5 Expressive collection operations Use array_first(), array_last(), array_find(), array_any() Symfony Polyfills All Back-port modern features to older runtimes Add for legacy projects (7.4 → 8.x)
  28. How to Start Modernising Your Code Today • Start small

    - replace constants with enums in new code. • Use readonly for DTOs and value objects you don’t want to mutate. • Add #[Override] gradually - catch hidden inheritance bugs early. • Refactor conditionals with match expressions for cleaner intent. • Try the pipe operator and array helpers where transformations stack.