SlideShare a Scribd company logo
PHP 7 – A look at the future
by Radu Murzea
25 July 2015
Agenda
 A bit of History
 Most important new features of PHP 7
 Mini-demo of each one
 Q&A
PHP – A bit of high-level history
PHP < 5
1995 - 2008
PHP with
most known
features
Zend
Engine 1
PHP – A bit of high-level history
PHP < 5
1995 - 2008 2004 - 2017
PHP 5
PHP with
most known
features
Zend
Engine 1
Zend
Engine 2
New
Object-Oriented
Model
PHP – A bit of high-level history
PHP < 5
1995 - 2008 2004 - 2017 2015 - ?
PHP 5 PHP 7
PHP with
most known
features
Zend
Engine 1
Zend
Engine 2
Zend
Engine 3
New
Object-Oriented
Model
Keep reading
AST-based Compilation
Separation of parser and compiler
 Higher Maintainability
 Decouple syntax issues from technical issues
Performance Improvement
 Usually 10 – 20 % faster
 But requires more memory
Removes many syntax limitations
 See “Uniform Variable Syntax” Chapter
Reference
 https://wiki.php.net/rfc/abstract_syntax_tree
AST
looks
like this
Uniform Variable Syntax
Consistent left-to-right variable dereferencing
 Stuff like this is now possible:
 $foo['bar']->baz->oof()::$rab
 explode(‘|’, $x)[3]
 $foo()[‘bar’]()
 foo()()
 (function() { return 1+2+3; })()
 ‘Foo’::$bar
Reference
 https://wiki.php.net/rfc/uniform_variable_syntax
Return Type Declarations (I)
Motivation
 Prevent unintended return values
 Document return type in a way that is not easily removed (like phpdoc
comments)
Rules
 In case of inheritance -> invariant enforcement
 If return type is declared, NULL may not be returned
 Not allowed on __construct(), __destruct() and __clone()
 Multiple return types are NOT allowed
Return Type Declarations (II)
Reference
 https://wiki.php.net/rfc/return_types
Example
class MyClass {
function a() { //return type is optional
return 123;
}
function b(): int { //fatal error - "int" doesn't exist
return 123;
}
function c(): ClassB { //fatal error - can't return null here
return null;
}
}
Anonymous Classes (I)
Motivation
 Anonymous classes are frequently used in other languages (Java, C#)
Basic Rules
 Instantiating requires providing values to constructor arguments
 Inheritance and Traits works just like for named classes
 Attempting to serialize will result in an ERROR
Use Cases
 In very simple cases, where dedicated file + class-doc = overkill
 When it’s small + you need it only once during execution
 When you don’t want to hit the autoloader for extremely simple classes
 Primitive support for situations where inner classes would make sense
Reference
 https://wiki.php.net/rfc/anonymous_classes
Anonymous Classes (II)
Examples
$x = new class(123) {
public function __construct($a) {
$this->a = $a;
}
};
(new class extends SomeClass implements SomeInterface {
public function init() { /* ... */ }
})->doStuff();
class MyClass extends MyOtherClass {
public function getInstance() {
return new class implements MyInt { /* ... */ };
}
}
Many Fatal Errors become Exceptions
Motivation
 Execution immediately aborted, cannot be recovered from
 finally blocks or __destructor() s are not called
Solution
Reference
 https://wiki.php.net/rfc/engine_exceptions_for_php7
 https://wiki.php.net/rfc/throwable-interface
 https://trowski.com/2015/06/24/throwable-exceptions-and-errors-in-php7/
Context Sensitive Lexer
Motivation
 PHP reserved words prevent good/natural API designs
Example
This is now possible:
Finder::for(‘project’)
->where(‘name’)->like(‘%secret%’)
->and(‘priority’, ‘>’, 9)
->or(‘code’)->in([‘4’, ‘5’, ‘7’])
->and()->not(‘created_at’)->between([$t1, $t2])
->list($limit, $offset);
Reference
 https://wiki.php.net/rfc/context_sensitive_lexer
Grouping Use Declarations (I)
Motivation
 Cut verbosity when importing classes, functions or constants
 Easier to identify which entities belong to the same module
Reference
 https://wiki.php.net/rfc/group_use_declarations
Example
This:
use FooBarStuffA;
use FooBarStuffB as MyB;
becomes this:
use FooBar{
StuffA,
StuffB as MyB
};
Null Coalesce Operator
Motivation
 Operations like “if data exists, use it; otherwise use default” are quite
cumbersome to do
Description/Examples
 Denoted by ??
 Returns result of 1st operand if it exists and is not NULL; otherwise
returns 2nd operand
 The following 2 statements are equivalent:
 $a = isset($_GET[‘a’]) ? $_GET[‘a’] : ‘default’;
 $a = $_GET[‘a’] ?? ‘default’;
 The following 2 statements are equivalent as well:
 if (($a = A::$value) === null) { $a = $default; }
 $a = A::$value ?? $default;
Reference
 https://wiki.php.net/rfc/isset_ternary
Unicode Code Point Escape Syntax
Motivation
 Proper escape syntax for Unicode characters
 Support for more than 16-bit-length BPM characters
 Syntax is u{xxxxxx} – with variable length
Examples
 echo "u{202E}Right-to-left text";
will print: txet tfel-ot-thgiR
 echo “u{1F602}”; //Emoji – Face with Tears of Joy
will print:
Reference
 https://wiki.php.net/rfc/unicode_escape
Performance – MediaWiki – Requests/s
 Source: http://talks.php.net/velocity15#/mwbench
Performance – Wordpress - Latency
 Source: http://talks.php.net/velocity15#/wpbench
Q & A

More Related Content

PPTX
PHP 7 - A look at the future
PPTX
PHP 7 Crash Course - php[world] 2015
PPTX
PHP slides
PDF
Last train to php 7
PDF
Php through the eyes of a hoster pbc10
ODP
PHP Barcelona 2010 - Architecture and testability
PPTX
Php.ppt
PHP 7 - A look at the future
PHP 7 Crash Course - php[world] 2015
PHP slides
Last train to php 7
Php through the eyes of a hoster pbc10
PHP Barcelona 2010 - Architecture and testability
Php.ppt

What's hot (20)

PPT
PPT
PHP Workshop Notes
PPTX
php basics
PPT
PDF
PHP7 is coming
PDF
Php introduction
PPT
Introduction to php php++
PPTX
PHP Basics
PPTX
Web-App Remote Code Execution Via Scripting Engines
PPTX
PDF
Introduction to PHP
PDF
Php a dynamic web scripting language
PPTX
PHP from soup to nuts Course Deck
PPTX
PPT
Php manish
PPTX
Constructor and encapsulation in php
PPT
Php Presentation
PDF
Introduction to php
PHP Workshop Notes
php basics
PHP7 is coming
Php introduction
Introduction to php php++
PHP Basics
Web-App Remote Code Execution Via Scripting Engines
Introduction to PHP
Php a dynamic web scripting language
PHP from soup to nuts Course Deck
Php manish
Constructor and encapsulation in php
Php Presentation
Introduction to php
Ad

Viewers also liked (6)

PDF
A new tool for measuring performance in Drupal 8 - Drupal Dev Days Montpellier
PDF
Caching with Memcached and APC
PDF
Optimizing Drupal Performance Zend Acquia Whitepaper Feb2010
PPT
How PHP Works ?
PPT
The Php Life Cycle
PDF
Apache Server Tutorial
A new tool for measuring performance in Drupal 8 - Drupal Dev Days Montpellier
Caching with Memcached and APC
Optimizing Drupal Performance Zend Acquia Whitepaper Feb2010
How PHP Works ?
The Php Life Cycle
Apache Server Tutorial
Ad

Similar to PHP7 - A look at the future (20)

PPS
Simplify your professional web development with symfony
ODP
Patterns in Python
 
PDF
PDF
PHP Frameworks: I want to break free (IPC Berlin 2024)
PPT
Edp bootstrapping a-software_company
ODP
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
PDF
Current state-of-php
PPTX
Spl in the wild - zendcon2012
ODP
Drupal Best Practices
PDF
Embrace dynamic PHP
PDF
Spl in the wild
PDF
Tips
PPTX
PowerShell 101
PDF
Building Web Applications with Zend Framework
PPS
003 web-apps-using-kohana-arafat-rahman-101107191139-phpapp02
PDF
Effective PHP. Part 4
PDF
Living With Legacy Code
KEY
PHP 5.3
PDF
Automatic testing and quality assurance for WordPress plugins and themes
PDF
Performance tuning with zend framework
Simplify your professional web development with symfony
Patterns in Python
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
Edp bootstrapping a-software_company
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Current state-of-php
Spl in the wild - zendcon2012
Drupal Best Practices
Embrace dynamic PHP
Spl in the wild
Tips
PowerShell 101
Building Web Applications with Zend Framework
003 web-apps-using-kohana-arafat-rahman-101107191139-phpapp02
Effective PHP. Part 4
Living With Legacy Code
PHP 5.3
Automatic testing and quality assurance for WordPress plugins and themes
Performance tuning with zend framework

Recently uploaded (20)

PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PPTX
Online Work Permit System for Fast Permit Processing
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Mastering-Cybersecurity-The-Crucial-Role-of-Antivirus-Support-Services.pptx
PDF
Become an Agentblazer Champion Challenge Kickoff
PPTX
Save Business Costs with CRM Software for Insurance Agents
PDF
Become an Agentblazer Champion Challenge
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Choose the Most Effective Social Media Agency in Bangalore.pdf
PPTX
How a Careem Clone App Allows You to Compete with Large Mobility Brands
PPTX
ai tools demonstartion for schools and inter college
PDF
System and Network Administration Chapter 2
PDF
Best Practices for Rolling Out Competency Management Software.pdf
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Materi_Pemrograman_Komputer-Looping.pptx
Online Work Permit System for Fast Permit Processing
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Mastering-Cybersecurity-The-Crucial-Role-of-Antivirus-Support-Services.pptx
Become an Agentblazer Champion Challenge Kickoff
Save Business Costs with CRM Software for Insurance Agents
Become an Agentblazer Champion Challenge
Upgrade and Innovation Strategies for SAP ERP Customers
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Choose the Most Effective Social Media Agency in Bangalore.pdf
How a Careem Clone App Allows You to Compete with Large Mobility Brands
ai tools demonstartion for schools and inter college
System and Network Administration Chapter 2
Best Practices for Rolling Out Competency Management Software.pdf
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes

PHP7 - A look at the future

  • 1. PHP 7 – A look at the future by Radu Murzea 25 July 2015
  • 2. Agenda  A bit of History  Most important new features of PHP 7  Mini-demo of each one  Q&A
  • 3. PHP – A bit of high-level history PHP < 5 1995 - 2008 PHP with most known features Zend Engine 1
  • 4. PHP – A bit of high-level history PHP < 5 1995 - 2008 2004 - 2017 PHP 5 PHP with most known features Zend Engine 1 Zend Engine 2 New Object-Oriented Model
  • 5. PHP – A bit of high-level history PHP < 5 1995 - 2008 2004 - 2017 2015 - ? PHP 5 PHP 7 PHP with most known features Zend Engine 1 Zend Engine 2 Zend Engine 3 New Object-Oriented Model Keep reading
  • 6. AST-based Compilation Separation of parser and compiler  Higher Maintainability  Decouple syntax issues from technical issues Performance Improvement  Usually 10 – 20 % faster  But requires more memory Removes many syntax limitations  See “Uniform Variable Syntax” Chapter Reference  https://wiki.php.net/rfc/abstract_syntax_tree AST looks like this
  • 7. Uniform Variable Syntax Consistent left-to-right variable dereferencing  Stuff like this is now possible:  $foo['bar']->baz->oof()::$rab  explode(‘|’, $x)[3]  $foo()[‘bar’]()  foo()()  (function() { return 1+2+3; })()  ‘Foo’::$bar Reference  https://wiki.php.net/rfc/uniform_variable_syntax
  • 8. Return Type Declarations (I) Motivation  Prevent unintended return values  Document return type in a way that is not easily removed (like phpdoc comments) Rules  In case of inheritance -> invariant enforcement  If return type is declared, NULL may not be returned  Not allowed on __construct(), __destruct() and __clone()  Multiple return types are NOT allowed
  • 9. Return Type Declarations (II) Reference  https://wiki.php.net/rfc/return_types Example class MyClass { function a() { //return type is optional return 123; } function b(): int { //fatal error - "int" doesn't exist return 123; } function c(): ClassB { //fatal error - can't return null here return null; } }
  • 10. Anonymous Classes (I) Motivation  Anonymous classes are frequently used in other languages (Java, C#) Basic Rules  Instantiating requires providing values to constructor arguments  Inheritance and Traits works just like for named classes  Attempting to serialize will result in an ERROR Use Cases  In very simple cases, where dedicated file + class-doc = overkill  When it’s small + you need it only once during execution  When you don’t want to hit the autoloader for extremely simple classes  Primitive support for situations where inner classes would make sense Reference  https://wiki.php.net/rfc/anonymous_classes
  • 11. Anonymous Classes (II) Examples $x = new class(123) { public function __construct($a) { $this->a = $a; } }; (new class extends SomeClass implements SomeInterface { public function init() { /* ... */ } })->doStuff(); class MyClass extends MyOtherClass { public function getInstance() { return new class implements MyInt { /* ... */ }; } }
  • 12. Many Fatal Errors become Exceptions Motivation  Execution immediately aborted, cannot be recovered from  finally blocks or __destructor() s are not called Solution Reference  https://wiki.php.net/rfc/engine_exceptions_for_php7  https://wiki.php.net/rfc/throwable-interface  https://trowski.com/2015/06/24/throwable-exceptions-and-errors-in-php7/
  • 13. Context Sensitive Lexer Motivation  PHP reserved words prevent good/natural API designs Example This is now possible: Finder::for(‘project’) ->where(‘name’)->like(‘%secret%’) ->and(‘priority’, ‘>’, 9) ->or(‘code’)->in([‘4’, ‘5’, ‘7’]) ->and()->not(‘created_at’)->between([$t1, $t2]) ->list($limit, $offset); Reference  https://wiki.php.net/rfc/context_sensitive_lexer
  • 14. Grouping Use Declarations (I) Motivation  Cut verbosity when importing classes, functions or constants  Easier to identify which entities belong to the same module Reference  https://wiki.php.net/rfc/group_use_declarations Example This: use FooBarStuffA; use FooBarStuffB as MyB; becomes this: use FooBar{ StuffA, StuffB as MyB };
  • 15. Null Coalesce Operator Motivation  Operations like “if data exists, use it; otherwise use default” are quite cumbersome to do Description/Examples  Denoted by ??  Returns result of 1st operand if it exists and is not NULL; otherwise returns 2nd operand  The following 2 statements are equivalent:  $a = isset($_GET[‘a’]) ? $_GET[‘a’] : ‘default’;  $a = $_GET[‘a’] ?? ‘default’;  The following 2 statements are equivalent as well:  if (($a = A::$value) === null) { $a = $default; }  $a = A::$value ?? $default; Reference  https://wiki.php.net/rfc/isset_ternary
  • 16. Unicode Code Point Escape Syntax Motivation  Proper escape syntax for Unicode characters  Support for more than 16-bit-length BPM characters  Syntax is u{xxxxxx} – with variable length Examples  echo "u{202E}Right-to-left text"; will print: txet tfel-ot-thgiR  echo “u{1F602}”; //Emoji – Face with Tears of Joy will print: Reference  https://wiki.php.net/rfc/unicode_escape
  • 17. Performance – MediaWiki – Requests/s  Source: http://talks.php.net/velocity15#/mwbench
  • 18. Performance – Wordpress - Latency  Source: http://talks.php.net/velocity15#/wpbench
  • 19. Q & A