Skip to main content

7 Reasons Why PHP 7 is Good

PHP 7 is the first major PHP release in over 10 years
Veli Akçakaya
Veli Akçakaya
3 min. read
PHP 7 yi İyi Yapan 7 Neden

Released in late 2015, PHP 7 is the first major PHP release in more than 10 years, bypassing PHP 6 to provide a more modern update. Some of its most useful features include.

  • Benchmark-Breaking Performance - 10 years isn't much of a time frame for far-reaching things, but when we look at it from an internet perspective, we see that it covers a very large chunk of that time frame. PHP has been restructured to not only reduce memory consumption but also improve performance. We can see that sites using PHP 7 are running faster than ever (and in many cases twice as fast).
  • Understandable Variable Syntax - In previous versions of PHP, some variable-variable expressions that were supposed to work were classed as invalid. PHP developers have made it even more consistent by developing more variable alternatives.
  • Spaceship Operator - Also known as the Unified Comparison Operator or the Three-Way Comparison operator. This operator's symbol <=> is called the Spaceship Operator because it looks like a spaceship in simple terms. This operator returns 0 if two values are equal, 1 if the left one is greater, and -1 if the right one is greater. In Perl and Ruby, this operator is already available as a directional comparison.
  • CSPRNG (Cryptographically Secure Pseudo Random Number Generator) - This function has a different use for PHP 7: a random number generator that makes it easier to generate passwords or complex passwords.
  • Scalar Type Hints - This feature has been available in PHP for over 10 years (e.g. when defining classes and arrays) and PHP 7 adds new ones: int, float, string, bool. This feature, as in other programming languages, allows you to create variables, assign values and catch errors based on the specified types.
    Anonymous Classes - Allows users to create objects without having to give them a name. In general, it is ideal for one-time object use. For more information, you can take a look at PHP's own website. http://php.net/manual/tr/language.oop5.anonymous.php
  • Return Type Declarations - Code is often better when it is easy to read. PHP 7 introduces new type declarations that not only make the code easier to read, but also allow the function to return the desired data type. You can see the new usage by looking at the example below. The trick is to specify the type to be returned by placing a : sign immediately after the function name.
  1. function helloDrupal() : string {
                       return "Merhaba Drupal !";
                    }

     

Our Offices

Drupart Locations

Our Officess

London

151 West Green Road, London, England

442038156478

[email protected]

Drupart R&D

GOSB Teknopark Hi-Tech Bina 3.Kat B3 Gebze - KOCAELİ

+90 262 678 8872

[email protected]

Newark

112 Capitol Trail Suite, A437 Newark DE, 19711

+17406666255

[email protected]

Wiesbaden

Hinterbergstraße 27
65207 Wiesbaden
Deutschland

+49 (0) 6151 – 492 70 23

[email protected]