SlideShare ist ein Scribd-Unternehmen logo
1 von 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
 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 very
common but 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

Weitere ähnliche Inhalte

Was ist angesagt? (20)

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
 
Introduction to php php++
Introduction to php php++Introduction to php php++
Introduction to php php++
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
 
PHP
PHPPHP
PHP
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
PHP
PHPPHP
PHP
 
PHP in one presentation
PHP in one presentationPHP in one presentation
PHP in one presentation
 
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
 
Constructor and encapsulation in php
Constructor and encapsulation in phpConstructor and encapsulation in php
Constructor and encapsulation in php
 
Php
PhpPhp
Php
 
Php manish
Php manishPhp manish
Php manish
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Ähnlich wie PHP 7 - A look at the future

Drupal 8 meets to symphony
Drupal 8 meets to symphonyDrupal 8 meets to symphony
Drupal 8 meets to symphonyBrahampal Singh
 
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 symfonyFrancois Zaninotto
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_companyGanesh 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 - zendcon2012Elizabeth Smith
 
Tips
TipsTips
Tipsmclee
 
Embrace dynamic PHP
Embrace dynamic PHPEmbrace dynamic PHP
Embrace dynamic PHPPaul Houle
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend FrameworkPhil Brown
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
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 themesOtto Kekäläinen
 
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-phpapp02Julio Pari
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101Thomas Lee
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend frameworkAlan Seiden
 

Ähnlich wie PHP 7 - 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
 
Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 
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...
 
PHP 5
PHP 5PHP 5
PHP 5
 
Spl in the wild - zendcon2012
Spl in the wild - zendcon2012Spl in the wild - zendcon2012
Spl in the wild - zendcon2012
 
Tips
TipsTips
Tips
 
Embrace dynamic PHP
Embrace dynamic PHPEmbrace dynamic PHP
Embrace dynamic PHP
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend Framework
 
Spl in the wild
Spl in the wildSpl in the wild
Spl in the wild
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
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
 
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
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
 
PHP 5.3
PHP 5.3PHP 5.3
PHP 5.3
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
 
Effective PHP. Part 4
Effective PHP. Part 4Effective PHP. Part 4
Effective PHP. Part 4
 

Mehr von Radu Murzea

The World of StackOverflow
The World of StackOverflowThe World of StackOverflow
The World of StackOverflowRadu Murzea
 
SymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developersSymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developersRadu Murzea
 
The World of PHP PSR Standards
The World of PHP PSR StandardsThe World of PHP PSR Standards
The World of PHP PSR StandardsRadu Murzea
 
Hack programming language
Hack programming languageHack programming language
Hack programming languageRadu Murzea
 
Hack Programming Language
Hack Programming LanguageHack Programming Language
Hack Programming LanguageRadu Murzea
 
Unit Testing in PHP
Unit Testing in PHPUnit Testing in PHP
Unit Testing in PHPRadu Murzea
 
HipHop Virtual Machine
HipHop Virtual MachineHipHop Virtual Machine
HipHop Virtual MachineRadu Murzea
 

Mehr von Radu Murzea (7)

The World of StackOverflow
The World of StackOverflowThe World of StackOverflow
The World of StackOverflow
 
SymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developersSymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developers
 
The World of PHP PSR Standards
The World of PHP PSR StandardsThe World of PHP PSR Standards
The World of PHP PSR Standards
 
Hack programming language
Hack programming languageHack programming language
Hack programming language
 
Hack Programming Language
Hack Programming LanguageHack Programming Language
Hack Programming Language
 
Unit Testing in PHP
Unit Testing in PHPUnit Testing in PHP
Unit Testing in PHP
 
HipHop Virtual Machine
HipHop Virtual MachineHipHop Virtual Machine
HipHop Virtual Machine
 

Kürzlich hochgeladen

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
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 CCTVshikhaohhpro
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
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 GoalsJhone kinadey
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
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.comFatema Valibhai
 
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...panagenda
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
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 ApplicationsAlberto González Trastoy
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
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...ICS
 

Kürzlich hochgeladen (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
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
 
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...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
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...
 

PHP 7 - 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  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 very common but 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