Recently, PHP has officially released the most updated version, 8.0.1 on the 7th January of 2021. So we always look forward to providing you with the most details of PHP, while you have the choice to upgrade or continue with your current version of PHP 7.x. We always recommend the latest version of PHP 7.x to you, as the latest versions are the fastest and most secure
There is no doubt, PHP is one of the most popular and dominant languages on the Internet. And we need to learn and cope up with the new features to get most out of this language. Lets get started on a review of the latest features.
What’s new in Version 8.0?
PHP Version 8.0 has come up with some great new features like the following:
- Named Parameters: PHP 8.0 allows named parameters during function or method calls in addition to traditional positional parameters, which helps a lot for new and experienced programmers. This will certainly make the function or method parameter names part of the public API. The non-standardized DocBlock @no-named-arguments expresses that the library does not provide backwards-compatibility for named parameters.
- Attributes: In PHP 8.0, Attributes allows declaring meta-data for functions, classes, properties, and parameters. Attributes map to PHP class names (declared with an Attribute itself), and they can be fetched programmatically with PHP Reflection API, which is a great feature of PHP 8.0.
- Constructor Properties: In the constructor, PHP 8.0 enables declaring the visibility (public, private, or protected) and type. Those properties will be registered as class properties with the same visibility and type they are declared in the constructor.This backwards-incompatible feature can help reduce boilerplate code when declaring value-object classes.
- Just-in-Time Compilation: The Just-in-time (JIT) Compilation is a great feature of PHP. PHP Opcache supports JIT. It’s been disabled by default, and if you enable it, JIT compiles and caches native instructions. It does not make a noticeable difference in IO-bound web applications, but provides a performance boost for CPU-heavy applications.
- Weak-Maps: A WeakMap is another new feature of PHP 8.0, which allows to store and associate arbitrary values for object keys, but without preventing the garbage collector from clearing it the object falls out of scope everywhere else. A WeakMap is similar to SplObjectStorage, as in both WeakMap and splObjectStorage use objects as the key, and allows storage of arbitrary values. However, a WeakMap does not prevent the object from collecting the garbage.
Functionality or Syntax Changes in PHP 8.0:
There have been some changes in 8.0 with previous versions and they are mentioned below-
- Default error reporting is set to `E_ALL`
- Inheritance rules are not applied to `private` class methods
- Calling non-static class methods statically result in a fatal error
- Apache Handler: Module name and file path changes
- Locale-independent `float` to `string` casting
- Class magic method signatures are strictly enforced
- `substr`, `iconv_substr`, `grapheme_substr` return empty string on out-of-bound offsets
- PHP Startup Errors are displayed by default
- GD Extension: Windows DLL file name changed from `php_gd2.dll` to `php_gd.dll`
- `crypt()` function requires `$salt` parameter
- PDO: Default error mode set to exceptions
- `@` Error Suppression operator does not silent fatal errors
- Trailing commas are allowed in parameter lists and closure `use` lists
- Implicit negative array key increments do not skip negative numbers
- `XMLWriter` objects replace `xmlwriter` resources
- OpenSSL: `resource` to object migration
- `XMLParser` objects replace `xml` resources
- String to number comparisons no longer coerce string to a number
- Strict type checks on arithmetic operators
- Sorting functions maintain positions of equal value items
- Internal function warnings now throw `TypeError` and `ValueError` exceptions
- Expressions can now `throw` Exceptions
- JSON extension is always available
- `catch` exceptions only by type
- `+`/`-` operators take higher precedence when used with concat (`.`) operator
- `CurlHandle` class objects replace curl handlers
- Fatal errors on incompatible method signatures
- Disabled functions behave as if they do not exist
- `GdImage` class objects replace GD image resources
- Assertions throw exceptions by default
- Sockets extension resources (`Socket` and `AddressInfo`) are class objects
BoltFlare support can assist you in the update should you need any additional help, although BoltFlare cannot offer any support for individual plugins that may be experiencing a conflict with the new PHP 8.0 or 8.0.1 version.