SlideShare a Scribd company logo
PHP 7 EVOLUTION
Александр Трищенко: PHP 7 Evolution
taken from https://wiki.php.net/phpng
Performance
taken from https://wiki.php.net/phpng
Performance
http://zsuraski.blogspot.com/2014/07/benchmarking-phpng.html
Performance
Removed deprecated functionality
Scalar types declaration
<?php
// Coercive mode
function sumOfInts(int ...$ints)
{ 
    return array_sum($ints); 
} 
var_dump(sumOfInts(2, '3', 4.1)); 
//int(9)
Return type declarations
<?php
function arraysSum(array ...$arrays): array
{ 
    return array_map(function(array $array): int { 
        return array_sum($array); 
    }, $arrays); 
} 
print_r(arraysSum([1,2,3], [4,5,6], [7,8,9])); 
/*
Array
(
[0] => 6
[1] => 15
[2] => 24
)
*/
Strict mode isn't strict enough
http://tryshchenko.com/archives/47
Unlike parameter type declarations, the type
checking mode used for return types depends
on the file where the function is defined, not
where the function is called. This is because
returning the wrong type is a problem with the
callee, while passing the wrong type is a
problem with the caller.
Null coalesce operator
<?php
// Fetches the value of $_GET['user'] and returns 'nobody' 
// if it does not exist. 
$username = $_GET['user'] ?? 'nobody'; 
// This is equivalent to: 
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody'; 
// Coalesces can be chained: this will return the first 
// defined value out of $_GET['user'], $_POST['user'], and 
// 'nobody'. 
$username = $_GET['user'] ?? $_POST['user'] ?? 'nobody'; 
Spaceship operator
<?php
// Integers
echo 1 <=> 1; // 0
echo 1 <=> 2; // -1
echo 2 <=> 1; // 1
// Floats
echo 1.5 <=> 1.5; // 0
echo 1.5 <=> 2.5; // -1
echo 2.5 <=> 1.5; // 1
// Strings
echo "a" <=> "a"; // 0
echo "a" <=> "b"; // -1
echo "b" <=> "a"; // 1
Constant arrays using define()
<?php
define('ANIMALS', [
'dog',
'cat',
'bird'
]);
echo ANIMALS[1]; // outputs "cat"
Group use declarations
use somenamespace{ClassA, ClassB, ClassC as C}; 
use function somenamespace{fn_a, fn_b, fn_c}; 
use const somenamespace{ConstA, ConstB, ConstC};
Generator Return Expressions
$gen = (function() { 
    yield 1; 
    yield 2; 
    return 3; 
})();
foreach ($gen as $val) { 
    echo $val, PHP_EOL; 
} 
echo $gen->getReturn(), PHP_EOL; 
//1 
//2 
//3
Generator delegation
function gen()
{ 
    yield 1; 
    yield from gen2(); 
} 
function gen2()
{ 
    yield 2; 
    yield 3; 
} 
foreach (gen() as $val) 
{ 
    echo $val, PHP_EOL; 
} 
/*
1
2
3 */
Integer division with intdiv()
var_dump(intdiv(10, 3)); //3
PHP-NG
https://nikic.github.io/2015/05/05/Internal-value-representation-in-PHP-7-part-1.html
New zval structure
HashTable size reduced from 72 to 56 bytes
Switch from dlmalloc to something similar to jemalloc
Reduced MM overhead to 5%
x64 support
Александр Трищенко: PHP 7 Evolution
Exceptions handling
interface Throwable
|- Exception implements Throwable
|- ...
|- Error implements Throwable
|- TypeError extends Error
|- ParseError extends Error
|- ArithmeticError extends Error
|- DivisionByZeroError extends ArithmeticError
|- AssertionError extends Error
https://trowski.com/2015/06/24/throwable-exceptions-and-errors-in-php7/
Exceptions handling
interface Throwable
{ 
    public function getMessage(): string; 
    public function getCode(): int; 
    public function getFile(): string; 
    public function getLine(): int; 
    public function getTrace(): array; 
    public function getTraceAsString(): string; 
    public function getPrevious(): Throwable; 
    public function __toString(): string;
}
How to use it now
try { 
    // Code that may throw an Exception or Error. 
} catch (Throwable $t) { 
    // Executed only in PHP 7, will not match in PHP 5.x 
} catch (Exception $e) { 
    // Executed only in PHP 5.x, will not be reached in PHP 7 
}
Type errors
function add(int $left, int $right) 
{ 
    return $left + $right; 
} 
try { 
    $value = add('left', 'right'); 
} catch (TypeError $e) { 
    echo $e->getMessage(); 
} 
// Argument 1 passed to add() must be of the type integer, string given
ParseError
try { 
    require 'file-with-parse-error.php';
} catch (ParseError $e) { 
    echo $e->getMessage(), "n"; 
} 
//PHP Parse error: syntax error, unexpected ':', expecting ';' or '{'
ArithmeticError
try { 
    $value = 1 << ­1; 
} catch (ArithmeticError $e) { 
    echo $e->getMessage(), "n"; 
} 
DivisionByZeroError
try { 
    $value = 1 << ­1; 
} catch (DivisionByZeroError $e) { 
    echo $e->getMessage(), "n"; 
}
AssertionError
try { 
    $value = 1 % 0; 
} catch (DivisionByZeroError $e) { 
    echo $e->getMessage(), "n"; 
} 
//Fatal error: Uncaught AssertionError: assert($test === 0)
Applying function
//PHP5 WAY 
PHP 
<?php
class TestClass { 
  protected $b = 'hello world'; 
} 
//function ­ getter 
$getB = function() { 
  return $this->b; 
  //pay attention, context is undefined now! 
}; 
$applied = $getB->bindTo(new TestClass, 'TestClass'); 
echo $applied();
Applying function
//PHP7 WAY 
<?php
class TestClass { 
  protected $b = 'hello world'; 
} 
  
//function ­ getter 
  
$getB = function() { 
  return $this->b; 
  //pay attention, context is undefined now! 
}; 
  
  
echo $getB->call(new TestClass);
Continue coming soon
Tryshchenko Oleksandr
Dataart 2015
ensaierwa@gmail.com
skype:ensaier
 
Александр Трищенко: PHP 7 Evolution

More Related Content

What's hot (20)

PPT
Php Chapter 1 Training
Chris Chubb
 
PDF
Advanced modulinos trial
brian d foy
 
PDF
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
DOCX
Authentication Functions
Valerie Rickert
 
DOC
The Truth About Lambdas in PHP
Sharon Levy
 
PDF
Advanced modulinos
brian d foy
 
PDF
SPL: The Missing Link in Development
jsmith92
 
PDF
ZF3 introduction
Vincent Blanchon
 
PDF
Practical JavaScript Programming - Session 6/8
Wilson Su
 
PPTX
A Functional Guide to Cat Herding with PHP Generators
Mark Baker
 
KEY
My Development Story
Takahiro Fujiwara
 
PDF
Zend Framework 2 : Dependency Injection
Abdul Malik Ikhsan
 
DOCX
PL/SQL Blocks
Anar Godjaev
 
PDF
Lazy Data Using Perl
Workhorse Computing
 
KEY
Decent exposure: Controladores sin @ivars
Leonardo Soto
 
PPT
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Anton Shemerey
 
PDF
Business Rules with Brick
brian d foy
 
PDF
14 Dependency Injection #burningkeyboards
Denis Ristic
 
PPTX
Class 8 - Database Programming
Ahmed Swilam
 
KEY
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Masahiro Nagano
 
Php Chapter 1 Training
Chris Chubb
 
Advanced modulinos trial
brian d foy
 
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
Authentication Functions
Valerie Rickert
 
The Truth About Lambdas in PHP
Sharon Levy
 
Advanced modulinos
brian d foy
 
SPL: The Missing Link in Development
jsmith92
 
ZF3 introduction
Vincent Blanchon
 
Practical JavaScript Programming - Session 6/8
Wilson Su
 
A Functional Guide to Cat Herding with PHP Generators
Mark Baker
 
My Development Story
Takahiro Fujiwara
 
Zend Framework 2 : Dependency Injection
Abdul Malik Ikhsan
 
PL/SQL Blocks
Anar Godjaev
 
Lazy Data Using Perl
Workhorse Computing
 
Decent exposure: Controladores sin @ivars
Leonardo Soto
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Anton Shemerey
 
Business Rules with Brick
brian d foy
 
14 Dependency Injection #burningkeyboards
Denis Ristic
 
Class 8 - Database Programming
Ahmed Swilam
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Masahiro Nagano
 

Similar to Александр Трищенко: PHP 7 Evolution (20)

PPTX
Php 7 - YNS
Alex Amistad
 
PDF
PHP 7.0 new features (and new interpreter)
Andrea Telatin
 
PDF
PHP7 - Scalar Type Hints & Return Types
Eric Poe
 
PDF
PHP7: Hello World!
Pavel Nikolov
 
PDF
PHP7 is coming
julien pauli
 
PDF
PHP7.1 New Features & Performance
Xinchen Hui
 
PDF
PHP Conference Asia 2016
Britta Alex
 
PPTX
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
DrupalMumbai
 
PDF
[4developers2016] PHP 7 (Michał Pipa)
PROIDEA
 
PPTX
PHP7 Presentation
David Sanchez
 
PDF
ElePHPant7 - Introduction to PHP7
Muhammad Hafiz Hasan
 
PDF
Php7 傳說中的第七隻大象
bobo52310
 
PDF
What's new in PHP 8.0?
Nikita Popov
 
PPTX
Learning php 7
Ed Lomonaco
 
PPTX
Peek at PHP 7
John Coggeshall
 
PDF
Php 5.6 From the Inside Out
Ferenc Kovács
 
PDF
Php 7 crash course
Khaireddine Hamdi
 
PPTX
New in php 7
Vic Metcalfe
 
PDF
Start using PHP 7
Oscar Merida
 
PDF
Giới thiệu PHP 7
ZendVN
 
Php 7 - YNS
Alex Amistad
 
PHP 7.0 new features (and new interpreter)
Andrea Telatin
 
PHP7 - Scalar Type Hints & Return Types
Eric Poe
 
PHP7: Hello World!
Pavel Nikolov
 
PHP7 is coming
julien pauli
 
PHP7.1 New Features & Performance
Xinchen Hui
 
PHP Conference Asia 2016
Britta Alex
 
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
DrupalMumbai
 
[4developers2016] PHP 7 (Michał Pipa)
PROIDEA
 
PHP7 Presentation
David Sanchez
 
ElePHPant7 - Introduction to PHP7
Muhammad Hafiz Hasan
 
Php7 傳說中的第七隻大象
bobo52310
 
What's new in PHP 8.0?
Nikita Popov
 
Learning php 7
Ed Lomonaco
 
Peek at PHP 7
John Coggeshall
 
Php 5.6 From the Inside Out
Ferenc Kovács
 
Php 7 crash course
Khaireddine Hamdi
 
New in php 7
Vic Metcalfe
 
Start using PHP 7
Oscar Merida
 
Giới thiệu PHP 7
ZendVN
 
Ad

More from Oleg Poludnenko (12)

PPTX
Дмитрий Красун: Сегодня вы уйдете с новым представлением о REST
Oleg Poludnenko
 
PPTX
Иван Стеценко: ЯП Zephir. Панацея или лечение?
Oleg Poludnenko
 
PPTX
Александр Трищенко: Phalcon framework
Oleg Poludnenko
 
PDF
Алексей Иванкин: Highload + PHP
Oleg Poludnenko
 
PPTX
Антон Довгоброд: Highload и очереди задач на примере PHP + Gearman + Yii2
Oleg Poludnenko
 
PPTX
Алексей Рыстенко: Highload и микросервисы
Oleg Poludnenko
 
PPTX
Алексей Плеханов: Новинки Laravel 5
Oleg Poludnenko
 
PDF
Макс Волошин: Php + shell = ♥
Oleg Poludnenko
 
PPTX
Дмитрий Тарасов: Google App Engine & PHP SDK
Oleg Poludnenko
 
PPTX
Алексей Рыстенко: Continuous Integration
Oleg Poludnenko
 
PPTX
Илья Андриенко: Вёрстка в проекте глазами “неверстальщика”
Oleg Poludnenko
 
PDF
Алексей Плеханов: 25 причин попробовать Laravel
Oleg Poludnenko
 
Дмитрий Красун: Сегодня вы уйдете с новым представлением о REST
Oleg Poludnenko
 
Иван Стеценко: ЯП Zephir. Панацея или лечение?
Oleg Poludnenko
 
Александр Трищенко: Phalcon framework
Oleg Poludnenko
 
Алексей Иванкин: Highload + PHP
Oleg Poludnenko
 
Антон Довгоброд: Highload и очереди задач на примере PHP + Gearman + Yii2
Oleg Poludnenko
 
Алексей Рыстенко: Highload и микросервисы
Oleg Poludnenko
 
Алексей Плеханов: Новинки Laravel 5
Oleg Poludnenko
 
Макс Волошин: Php + shell = ♥
Oleg Poludnenko
 
Дмитрий Тарасов: Google App Engine & PHP SDK
Oleg Poludnenko
 
Алексей Рыстенко: Continuous Integration
Oleg Poludnenko
 
Илья Андриенко: Вёрстка в проекте глазами “неверстальщика”
Oleg Poludnenko
 
Алексей Плеханов: 25 причин попробовать Laravel
Oleg Poludnenko
 
Ad

Recently uploaded (20)

PDF
Market Wrap for 18th July 2025 by CIFDAQ
CIFDAQ
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PDF
How Current Advanced Cyber Threats Transform Business Operation
Eryk Budi Pratama
 
PDF
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
HR agent at Mediq: Lessons learned on Agent Builder & Maestro by Tacstone Tec...
UiPathCommunity
 
PDF
Upskill to Agentic Automation 2025 - Kickoff Meeting
DianaGray10
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Novus-Safe Pro: Brochure-What is Novus Safe Pro?.pdf
Novus Hi-Tech
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Upgrading to z_OS V2R4 Part 01 of 02.pdf
Flavio787771
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Market Wrap for 18th July 2025 by CIFDAQ
CIFDAQ
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
How Current Advanced Cyber Threats Transform Business Operation
Eryk Budi Pratama
 
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
HR agent at Mediq: Lessons learned on Agent Builder & Maestro by Tacstone Tec...
UiPathCommunity
 
Upskill to Agentic Automation 2025 - Kickoff Meeting
DianaGray10
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Novus-Safe Pro: Brochure-What is Novus Safe Pro?.pdf
Novus Hi-Tech
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Upgrading to z_OS V2R4 Part 01 of 02.pdf
Flavio787771
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 

Александр Трищенко: PHP 7 Evolution