- Edited
https://www.php.net/releases/8.0/en.php
-
Union Types (for properties that might need to hold values of different types)
-
Named arguments (so that your functions can have more parameters without bogging your users down in piles of useless default arguments). Guess what? Now you have to be more responsible in how you name your function parameters because they're now a visible part of your API.
-
Match expressions (they're like a more compact switch statement, or a more sophisticated (and type-safe) lookup table, that can appear inside an expression; for when an array isn't enough but a switch is too much).
-
Attributes (instead of relying on ad-hoc doc comment annotations that might or might not make sense to your IDE).
-
Constructor Property Promotion (when all your constructor does is initialise a bunch of properties from its arguments, now all three steps can be done at once).
-
Nullsafe access operator (
$foo->bar()
is an error if$foo
happens to be null.$foo?->bar()
is null if$foo
is null). -
Weak maps (a weak map won't stop its contents from being garbage-collected; if a value isn't used anywhere else, the weak map will discard it as well).
-
Etc. etc.
A new major version of PHP has just been released, with quite a few new language features, some old sillinesses corrected, and, oh, a JIT compiler.
Because major versions are where backward-compatibility breaks are allowed, reading the migration documentation is a must. For example, features that were deprecated in PHP 7 are now gone. Error reporting is more aggressive. A number of resource types have been replaced by classes.
But possibly the most important thing to pay attention to is the fact that 0=="foo"
is now false instead of the old and infamous silliness of true. What happens now when you compare a number to a string is that the string is checked to see if it even looks like a number. Strings that don't look like numbers aren't equal to numbers.