Slide 1

Slide 1 text

Modern PHP Features You're Probably Not Using (But Should Be) Paul Conroy / @conroyp 30th October, 2025

Slide 2

Slide 2 text

From Dublin, Ireland Started playing with the web 30+ years ago (Notepad, Frontpage & Geocities!) CTO at Square1 conroyp.com / @conroyp Paul Conroy ๐Ÿ‘ด ๐ŸŒ ๐Ÿ‡ฎ๐Ÿ‡ช

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Latest & Greatest PHP Features

Slide 5

Slide 5 text

Latest & Greatest PHP Features โ— Bugfixes

Slide 6

Slide 6 text

Latest & Greatest PHP Features โ— Bugfixes โ— Deadlines

Slide 7

Slide 7 text

Latest & Greatest PHP Features โ— Bugfixes โ— Deadlines โ— The Day Job

Slide 8

Slide 8 text

Latest & Greatest PHP Features โ— Bugfixes โ— Deadlines โ— The Day Job โ— Getting Paid!

Slide 9

Slide 9 text

https://stitcher.io/blog/php-version-stats-june-2025

Slide 10

Slide 10 text

https://stitcher.io/blog/php-version-stats-june-2025

Slide 11

Slide 11 text

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.

Slide 12

Slide 12 text

Strong & Stable Core

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

๐Ÿ˜ฑ

Slide 15

Slide 15 text

๐Ÿ˜ฑ

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

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!

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

๐Ÿค” โ‰โ‰โ‰

Slide 25

Slide 25 text

๐Ÿค” โ‰โ‰โ‰

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Input Validation

Slide 34

Slide 34 text

Input Validation

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

โ— Move the logic closer to what it represents. โ— Single place to check role-related logic.

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

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.

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

?? โ‡ โ— Function starts out obvious.โ€จ โ— Params added over time - flags!โ€จ โ— Readability isnโ€™t great.

Slide 47

Slide 47 text

?? โ‡ โ— Function starts out obvious.โ€จ โ— Params added over time - flags!โ€จ โ— Readability isnโ€™t great.

Slide 48

Slide 48 text

Named Arguments

Slide 49

Slide 49 text

Named Arguments

Slide 50

Slide 50 text

Named Arguments โ— Makes the code obvious.โ€จ โ— Refactor-safe.โ€จ โ— Impossible to misorder.โ€จ โ— Suitable for long parameter lists.

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

// Donโ€™t care about this!

Slide 53

Slide 53 text

// Donโ€™t care about this!

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

โŒ Easy to accidentally mutate after instantiation โŒ No enforcement of immutability โŒ Bugs creep in when state is shared across layers

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

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!)

Slide 67

Slide 67 text

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!)

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

The Robots will figure it outโ€ฆ

Slide 80

Slide 80 text

The Robots will figure it outโ€ฆ

Slide 81

Slide 81 text

The Robots will figure it outโ€ฆ

Slide 82

Slide 82 text

The Robots will figure it outโ€ฆ

Slide 83

Slide 83 text

The Robots will figure it outโ€ฆ

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

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.

Slide 88

Slide 88 text

Framing the Structure

Slide 89

Slide 89 text

Switch it up

Slide 90

Slide 90 text

Switch it up

Slide 91

Slide 91 text

Switch it up

Slide 92

Slide 92 text

Switch it up

Slide 93

Slide 93 text

Switch it up ๐Ÿ”ต ๐Ÿ”ต

Slide 94

Slide 94 text

Switch it up ๐Ÿ”ต ๐Ÿ”ต ๐ŸŸก ๐ŸŸก

Slide 95

Slide 95 text

Switch it up ๐Ÿ”ต ๐Ÿ”ต ๐ŸŸก ๐ŸŸก โšช โšช

Slide 96

Slide 96 text

Switch it up

Slide 97

Slide 97 text

Switch it up

Slide 98

Slide 98 text

Match Expression

Slide 99

Slide 99 text

Match Expression

Slide 100

Slide 100 text

Match Expression โ— Closer to if/else functionality โ— No fallthrough โ— Strict comparisons (===) โ— Must return a value!

Slide 101

Slide 101 text

(De)faulty switch

Slide 102

Slide 102 text

(De)faulty switch

Slide 103

Slide 103 text

(De)faulty switch

Slide 104

Slide 104 text

(De)faulty switch

Slide 105

Slide 105 text

(De)faulty switch

Slide 106

Slide 106 text

(De)faulty switch โ— default is easy to miss. โ— Silent failure in switch case. โ— Very loud failure with match!

Slide 107

Slide 107 text

Strongly typed

Slide 108

Slide 108 text

Strongly typed

Slide 109

Slide 109 text

Strongly typed

Slide 110

Slide 110 text

Strongly typed

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

โ— Checking what condition matches โ€œtrueโ€โ€จ โ— First match wins!

Slide 116

Slide 116 text

โ— Checking what condition matches โ€œtrueโ€โ€จ โ— First match wins!

Slide 117

Slide 117 text

FizzBuzz https://www.php.net/manual/en/control-structures.match.php#125987

Slide 118

Slide 118 text

FizzBuzz https://www.php.net/manual/en/control-structures.match.php#125987

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

Union Types

Slide 123

Slide 123 text

Union Types โ— Comment isnโ€™t a contract!

Slide 124

Slide 124 text

Union Types โ— Comment isnโ€™t a contract! โ— Pass in precise types. โ— Not relying on docblocks.

Slide 125

Slide 125 text

Intersection Types

Slide 126

Slide 126 text

Intersection Types

Slide 127

Slide 127 text

Intersection Types

Slide 128

Slide 128 text

Intersection Types

Slide 129

Slide 129 text

Intersection Types

Slide 130

Slide 130 text

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!

Slide 131

Slide 131 text

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

Slide 132

Slide 132 text

Making It A Home

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

Property Hooks

Slide 135

Slide 135 text

Property Hooks

Slide 136

Slide 136 text

Property Hooks

Slide 137

Slide 137 text

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#

Slide 138

Slide 138 text

Property Hooks

Slide 139

Slide 139 text

Property Hooks - Interfaces

Slide 140

Slide 140 text

โ— Pragmatic, not dogmatic. โ— Still uniquely PHP. โ— Evolves & matures by learning.

Slide 141

Slide 141 text

โ— Pragmatic, not dogmatic. โ— Still uniquely PHP. โ— Evolves & matures by learning.

Slide 142

Slide 142 text

No content

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

No content

Slide 145

Slide 145 text

Pipe Operator

Slide 146

Slide 146 text

Pipe Operator

Slide 147

Slide 147 text

Pipe Operator

Slide 148

Slide 148 text

Pipe Operator

Slide 149

Slide 149 text

Arrays

Slide 150

Slide 150 text

Arrays

Slide 151

Slide 151 text

No content

Slide 152

Slide 152 text

No content

Slide 153

Slide 153 text

โŒ No syntax error โŒ Wrong function is running โŒ Silent failure!

Slide 154

Slide 154 text

#[Override] Attribute

Slide 155

Slide 155 text

#[Override] Attribute ๐Ÿšจ Previously was a warning โŒ Fatal error in 8.5

Slide 156

Slide 156 text

#[Override] Attribute

Slide 157

Slide 157 text

#[Override] Attribute

Slide 158

Slide 158 text

#[Override] Attribute

Slide 159

Slide 159 text

#[Override] Attribute

Slide 160

Slide 160 text

#[Override] Attribute Refactor-safe!

Slide 161

Slide 161 text

https://stitcher.io/blog/php-version-stats-june-2025

Slide 162

Slide 162 text

https://stitcher.io/blog/php-version-stats-june-2025

Slide 163

Slide 163 text

https://stitcher.io/blog/php-version-stats-june-2025

Slide 164

Slide 164 text

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โ€!

Slide 165

Slide 165 text

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!

Slide 166

Slide 166 text

Build With Better Materials โ— Clearer intent โ— Safer defaults โ— Expressive data โ— Predictable behaviour

Slide 167

Slide 167 text

Build With Better Materials โ— Clearer intent โ— Safer defaults โ— Expressive data โ— Predictable behaviour

Slide 168

Slide 168 text

Build With Better Materials โ— Clearer intent โ— Safer defaults โ— Expressive data โ— Predictable behaviour

Slide 169

Slide 169 text

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

Slide 170

Slide 170 text

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

Slide 171

Slide 171 text

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)

Slide 172

Slide 172 text

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.

Slide 173

Slide 173 text

Enjoy a better app, and an easier life!

Slide 174

Slide 174 text

No content

Slide 175

Slide 175 text

Conroyp.com @conroyp [email protected] ๐ŸŒ ๐ŸŒ Thank you! ๐Ÿ“ง