Awesome features of PHP 8

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 strpossubstrstrncmp, 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

  • Error reporting
  • Debugging
  • Business logic
  • By Tsuki



    アプリ関連ニュース

    お問い合わせはこちら

    お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

    tel. 06-6454-8833(平日 10:00~17:00)

    お問い合わせフォーム