Skip to content

PHP Tutorial Getting Started with PHP

PHP Versions and Modern PHP

Lesson 6 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

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, readonly properties, first-class callable syntax and the never return type.
  • PHP 8.2 (2022): readonly classes 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:

terminal
BASH
php -v

Or ask PHP from inside a script:

index.php
PHP
<?php
echo "You are running PHP " . PHP_VERSION;
Output
OUTPUT
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.
dangerous
Check the version on your host
Many shared hosts let you choose the PHP version in their control panel. If a lesson says “needs PHP 8.4” and your host runs 8.2, that code will give a parse error. See Installing PHP for how to check.