SlideShare uma empresa Scribd logo
1 de 19
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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
php basics
php basicsphp basics
php basics
 
PHP
PHPPHP
PHP
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Introduction to php php++
Introduction to php php++Introduction to php php++
Introduction to php php++
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Web-App Remote Code Execution Via Scripting Engines
Web-App Remote Code Execution Via Scripting EnginesWeb-App Remote Code Execution Via Scripting Engines
Web-App Remote Code Execution Via Scripting Engines
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
PHP
PHPPHP
PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
Php
PhpPhp
Php
 
Php manish
Php manishPhp manish
Php manish
 
Constructor and encapsulation in php
Constructor and encapsulation in phpConstructor and encapsulation in php
Constructor and encapsulation in php
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Destaque

The Php Life Cycle
The Php Life CycleThe Php Life Cycle
The Php Life Cycle
Xinchen Hui
 

Destaque (6)

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

Semelhante a PHP7 - A look at the future

Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
Ganesh Kulkarni
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
King Foo
 
Spl in the wild - zendcon2012
Spl in the wild - zendcon2012Spl in the wild - zendcon2012
Spl in the wild - zendcon2012
Elizabeth Smith
 
Tips
TipsTips
Tips
mclee
 
003 web-apps-using-kohana-arafat-rahman-101107191139-phpapp02
003 web-apps-using-kohana-arafat-rahman-101107191139-phpapp02003 web-apps-using-kohana-arafat-rahman-101107191139-phpapp02
003 web-apps-using-kohana-arafat-rahman-101107191139-phpapp02
Julio Pari
 

Semelhante a PHP7 - A look at the future (20)

Drupal 8 meets to symphony
Drupal 8 meets to symphonyDrupal 8 meets to symphony
Drupal 8 meets to symphony
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
PHP 5
PHP 5PHP 5
PHP 5
 
Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 
Spl in the wild - zendcon2012
Spl in the wild - zendcon2012Spl in the wild - zendcon2012
Spl in the wild - zendcon2012
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Embrace dynamic PHP
Embrace dynamic PHPEmbrace dynamic PHP
Embrace dynamic PHP
 
Spl in the wild
Spl in the wildSpl in the wild
Spl in the wild
 
Tips
TipsTips
Tips
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend Framework
 
003 web-apps-using-kohana-arafat-rahman-101107191139-phpapp02
003 web-apps-using-kohana-arafat-rahman-101107191139-phpapp02003 web-apps-using-kohana-arafat-rahman-101107191139-phpapp02
003 web-apps-using-kohana-arafat-rahman-101107191139-phpapp02
 
Effective PHP. Part 4
Effective PHP. Part 4Effective PHP. Part 4
Effective PHP. Part 4
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
PHP 5.3
PHP 5.3PHP 5.3
PHP 5.3
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themes
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
 

Último

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Último (20)

LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 

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