You will find old PHP code all over the internet. Some of it was written for PHP 5, which is long out of date. Knowing the story helps you read old code and avoid copying old habits.
A short history
- PHP 5 (2004): added proper object-oriented features. Many old tutorials and plugins still come from this time.
- PHP 7 (2015): a big speed-up, scalar type declarations, return types and the
??operator. The version number 6 was skipped. - PHP 8.0 (2020): named arguments, union types,
match, the nullsafe operator?->, constructor property promotion, attributes and a JIT compiler. - PHP 8.1 (2021): enums,
readonlyproperties, first-class callable syntax and theneverreturn type. - PHP 8.2 (2022):
readonlyclasses and more type options. - PHP 8.3, 8.4 and 8.5 (2023 to 2025): typed class constants, property hooks, asymmetric visibility, new array functions such as
array_find(), and the pipe operator in 8.5.
You will meet these features one at a time, and each lesson says which version it needs.
Which version should you use?
Use a version that still gets security fixes. The page php.net/supported-versions.php lists the supported branches and their end dates. Older versions stop receiving fixes, which is a real security risk on a public site.
To see which version you have, run this in a terminal:
php -v
Or ask PHP from inside a script:
<?php
echo "You are running PHP " . PHP_VERSION;
You are running PHP 8.4.1
Your number will be different. That line is only an example.
How this course treats versions
- The main course teaches habits that work on PHP 8.1 and newer: typed parameters,
match, enums and so on. - Features that need 8.3, 8.4 or 8.5 are marked with their version, so you know when an older server will reject them.
- Old patterns are shown only when you are likely to meet them in legacy code, and they are labelled as old.