Exploring PHP 7
& its new features

Presented by   Gokul NK & Sandeep Reddy

AzriSolutions

Gokul N K

  • Graduated from Rashtreeya Vidyalaya (RVCE)
  • From Bangalore
  • Drupal Architect at Azri Solutions
  • Formerly a Java Developer @ Mindtree
  • Drupal since 2011
  • Lead Maintainer for Automatr Module
  • Cofounder of Aziteez
  • Bowling Addict

Sandeep Reddy

  • Graduated from R.L.Jallapa Institue Of Technology
  • From Hyderabad
  • Technical architect at Azri Solutions
  • Cake php, Magento, Symfony Developer
  • Drupal since 2016
  • Cricket, Badmitton Addict

Overview

  • Where did PHP 6 go?
  • Performance
  • Scalar Type Declarations
  • New Operators
  • Other new features(syntaxes) in PHP7
  • Error Handling
  • Cryptographically Secure PseudoRandom Number Generator in PHP
  • Backward incompatible changes in PHP 7
  • Demo : Benchmarking a Drupal 8 site in php 5.6 and php 7

Where did PHP 6 go?

  • PHP 6 already existed
  • To avoid confusion
  • Version 6 is generally associated with failure in the world of dynamic languages
  • https://wiki.php.net/rfc/php6

Performance

  • This will be the feature that you will hear most about PHP 7 and rightly So.
  • PHP has always underperformed compared to Java and this comes as a relief.

Twice the Speed

  • 39% say speed is more important than functionality for most websites, while only one in five rank greater site functionality as more important.

    Source : www.webperformancetoday.com/

What is PHP#NG (Next Generation).

  • A new branch of php that was concentrating on the performance
  • Now part of PHP 7.0
  • https://wiki.php.net/rfc/phpng

Enhancements in PHP#NG

  • Core data structures re-factoring
  • Better VM calling convention
  • Yet another new memory manager
  • Many improvements in VM executor
  • Significantly reduced memory usage
  • Improved character searching in strings
  • Improved string concatenation
  • Improved __call() and __callStatic() functions
  • Core data structures re-factoring

Speed comparison between PHP, Ruby, Python and Perl.

Source : http://www.zend.com/en/resources/php7_infographic.png

Benchmarks of Drupal with php 5.6 and 7

Source : http://www.zend.com/en/resources/php7_infographic.png

Scalar Type Declarations

  • Ensures better input consistency
  • By default weak type checking
  • Strict type-checking mode per file

Coercive Mode

  • Type hinting
  • Doesn't produce any errors

Strict Mode

  • declare(strict_types=1);
  • Type enforcement
  • Produced Fatal error: Uncaught TypeError:

Example

								
								/**
								 * Return type declarations
								 */
								//declare(strict_types=1);
								function add(int $a, int $b){
								    return (string)($a + $b);
								}
								
								

Return Type Declarations

  • Ensures Output consistency
  • We use a colon before the opening curly brace to hint/enforce the return type.

Example

								
								/**
								 * Return type declarations
								 */
								//declare(strict_types=1);
								function add(int $a, int $b): int{
								    return (string)($a + $b);
								}

								
								

New Operators

Null Coalesching Operators

Spaceship operator

Other new features(syntaxes) in PHP7.

  • Process Once Use Multiple Times.

Group use declarations

  • Cache Hit.

Anonymous classes

Error Handling

  • Cache invalidation,

Engine Exceptions

  • What are engine exceptions
  • Should we consider using Engine Exceptions and under what circumstances it makes sense to use them.

Cryptographically Secure PseudoRandom Number Generator in PHP.

  • Cache contexts are analogous to HTTP's Vary header.

Backward incompatible changes in PHP 7

  • Cache contexts are analogous to HTTP's Vary header.

PHP 7 virtualbox with Drupal VM

  • Cache contexts are analogous to HTTP's Vary header.

Demo : Benchmarking a Drupal 8 site in php 5.6 and php 7

  • Cache contexts are analogous to HTTP's Vary header.

Reference Links

Thank You!

Gokul NK

Questions?

Ask Google!