Awesome features of PHP 8
- 2022年3月03日
- Web Service
PHP 8 has been officially released for general users. PHP 8 brings a host of new features improvements, functions, and deprecations to the language compared to PHP 7. Among all of these new features, the JIT compiler is the one sharing the limelight. However, other features like syntax changes are also to be taken into account as it is these features that will have a greater impact on the practitioners.
New features include:
- Named arguments
- Union types
- Constructor property promotion
- Custom object serialization
- Match expression
- Nullsafe operator
- Improvements in the type system and error handling
New PHP Functions
- New str_contains() function
- New str_starts_with() and str_ends_with() functions
- New fdiv() function
- get_debug_type() function
— str_contains()
Helps us in determining whether the given sub-string is present inside the string.
Example :
str_contains ( string $austin , string $tin ) : bool
Executes a case-sensitive operations and checks whether the string austin contains the substring tin.
— string_starts_with and str_ends_with()
Using this function we can easily find whether the given sub-string is at the beginning or ending of the string.
Example:
str_starts_with(string $austin, string $au): bool;
str_ends_with(string $austin, string $tin): bool;
These new functions can be impersonated with strpos
, substr
, strncmp
, and substr_compare
. However, the new functions were favourably received due to its engine-level optimizations and their regular use cases.
— fdiv()
The new fdiv() function has similar ability as the fmod() and intdiv() functions, that allows for division by 0. Instead of getting errors, you’ll get INF, -INF, or NAN, depending on the scenario.
— get_debug_type()
The new get_debug_type function always returns the true native type of variables. It returns a return native type names, e.g., int rather than integer, double instead of float.
get_debug_type() function helps in
By Tsuki
tsuki at 2022年03月03日 10:00:00