DEV Community

Serhii Klochko
Serhii Klochko

Posted on

PHP 8.0, 8.1, 8.2, 8.3... what's new?! CheatSheet.

The idea of this note is to write down PHP 8+ what's news briefly, so they are visible all at once on a single page. Like a cheat-sheet.

Keep in mind that these are just the basic features, see each version's link for more details.

PHP 8.0 What's new

  • Named function arguments (i.e. arg_name: value, instead of filling preceding default arguments)
  • Attributes (instead of DocBlock comments)
  • Constructor property promotion (properties in constructor instead of normal declaration)
  • Union types (i.e. int|string $varname)
  • Match expression (to replace some of switch-case)
  • Nullsafe operator (instead of nesteds ifs)
  • Saner string to number comparisons (i.e. 0 == 'somestrval' // not true anymore)
  • Consistent type errors for internal functions (internal functions throws typed exceptions now)
  • Just-In-Time compilation (2x performance in some specific long-running applications)
  • and more

PHP 8.1 What's new

  • Enumerations (enums)
  • Readonly Properties (for VO and DTO)
  • First-class Callable Syntax (to get a reference to any function, i.e. $fn = strlen(...);)
  • New in initializers (for nested attributes)
  • Pure Intersection Types (Iterator&Countable $value but not A&B|C)
  • Never return type (to be clear that function returns nothing)
  • Final class constants (cannot override functions and inherit classes)
  • Explicit Octal numeral notation // TODO: add some description below
  • Fibers
  • Array unpacking support for string-keyed arrays
  • and more

PHP 8.2 What's new

  • Readonly classes
  • Disjunctive Normal Form (DNF) Types
  • Allow null, false, and true as stand-alone types
  • New "Random" extension
  • Constants in traits
  • Deprecate dynamic properties
  • and more

PHP 8.3. What's new

  • Typed class constants
  • Dynamic class constant fetch
  • New #[\Override] attribute
  • Deep-cloning of readonly properties
  • New json_validate() function
  • New Randomizer::getBytesFromString() method
  • New Randomizer::getFloat() and Randomizer::nextFloat() methods
  • Command line linter supports multiple files
  • and more

Top comments (2)

Collapse
 
snehalkadwe profile image
Snehal Rajeev Moon

Very informative cheatsheet. Thank you for sharing.

Collapse
 
graceman9 profile image
Serhii Klochko

Just realized I forgot to add one VERY useful link, if you need to migrate between PHP versions, it also includes PHP 7.x:

php.net/manual/en/history.php