SlideShare uma empresa Scribd logo
1 de 23
Introducing new version
Version 1.2 - 6/08/2015
Table of contents
● Preamble
● PHP5.6: in case you missed something
a. Overview
b. New features
● PHP7: future is coming
a. Overview
b. What's new
Preamble
● Use filter_var()
// Check valid email
bool filter_var('example@site.tld', FILTER_VALIDATE_EMAIL);
// Remove empty values
$data = array(
'value1' => '',
'value2' => null,
'value3' => []
);
filter_var_array($data); // return empty array
● Speed the code
DON'T open/close PHP tags for excessive.
DON'T use GLOBALS
● release date: August 2014
● PHP5: last branch release
PHP5.6: Overview
PHP5.6: New features
● Constant expressions
const ONE = 1;
// Scalar Expression in constant
const TWO = ONE * 2;
● Variadic functions/Argument unpacking
function myTools($name, ...$tools) {
echo "Name:". $name.'<br />';
echo "My Tool Count:". count(tools);
}
myTools('Avinash', 'Eclipse');
myTools('Avinash', 'Eclipse', 'Sublime');
myTools('Avinash', 'Eclipse', 'Sublime', 'PHPStorm');
function myTools($name, $tool1, $tool2, $tool3) {
echo "Name:". $name.'<br />';
echo "Tool1:", $tool1.'<br />';
echo "Tool2:", $tool2.'<br />';
echo "Tool3:", $tool3;
}
$myTools = ['Eclipse', 'Sublime', 'PHPStorm'];
myTools('Avinash', ...$myTools);
PHP5.6: New features
● Exponentiation
// PHP5.5 and before
pow(2, 8); // 256
// PHP5.6 and after
echo 2 ** 8; // 256
echo 2 ** 2 ** 4; // 256
● use function and use const
namespace NameSpace {
const FOO = 42;
function f() { echo __FUNCTION__."n"; }
}
namespace {
use const NameSpaceFOO;
use function NameSpacef;
echo FOO."n";
f();
}
PHP5.6: New features
● phpdbg: The interactive debugger
http://phpdbg.com/docs
● php://input
// Now deprecated
$HTTP_RAW_POST_DATA
// This is now reusable
file_get_contents('php://input');
● Large file uploads
Files larger than 2 gigabytes in size are now accepted.
PHP5.6: New features
● __debugInfo()
class C {
private $prop;
public function __construct($val) {
$this->prop = $val;
}
public function __debugInfo() {
return [
'propSquared' => $this->prop ** 2,
];
}
}
var_dump(new C(42));
object(C)#1 (1) {
["propSquared"]=>
int(1764)
}
● Release date: October 2015
● Engine: Zend v3 (32/64 bits)
● Performance: 25% to 70% faster
● Backward Incompatible Changes
● New Parser
● Tidy up old things
● Many new features
PHP7: Overview
● Scalar Type Declarations
// must be the first statement in a file.
// If it appears anywhere else in the file it will generate a compiler error.
declare(strict_types=1);
// Available type hints
int, float, string, bool
// Examples
function add(string $a, string $b): string {
return $a + $b;
}
function add(int $a, int $b): int {
return $a + $b;
}
function add(float $a, float $b): float {
return $a + $b;
}
function add(bool $a, bool $b): bool {
return $a + $b;
}
PHP7: What's new
● Group Use Declarations
// PHP7
use FooLibraryBarBaz{ ClassA, ClassB, ClassC, ClassD as Fizbo };
// Before PHP7
use FooLibraryBarBazClassA;
use FooLibraryBarBazClassB;
use FooLibraryBarBazClassC;
use FooLibraryBarBazClassD as Fizbo;
● switch.default.multiple
Will raise E_COMPILE_ERROR when multiple default blocks are found in a switch statement.
PHP7: What's new
● Alternative PHP tags removed
<% // opening tag
<%= // opening tag with echo
%> // closing tag
(<scripts+languages*=s*(php|"php"|'php')s*>)i // opening tag
(</script>)i // closing tag
● Return Type Declarations
// Returning array // Overriding a method that did not
have a return type:
function foo(): array { interface Comment {}
return []; interface CommentsIterator extends
Iterator {
} function
current(): Comment;
}
// Returning object
interface A {
static function make(): A;
}
class B implements A {
static function make(): A {
return new B();
}
}
PHP7: What's new
● Update json parser extension
json extension has been replaced by jsond extension
echo json_encode(10.0); // Output 10
echo json_encode(10.1); // Output 10.1
echo json_encode(10.0, JSON_PRESERVE_ZERO_FRACTION); // Output 10.0
echo json_encode(10.1, JSON_PRESERVE_ZERO_FRACTION); // Output 10.1
var_dump(json_decode(json_encode(10.0, JSON_PRESERVE_ZERO_FRACTION))); // Output double(10)
var_dump(10.0 === json_decode(json_encode(10.0, JSON_PRESERVE_ZERO_FRACTION))); // Output bool(true)
● Removing old codes
PHP4 constructor
Removal of dead/unmaintained/deprecated SAPIs and extensions (imap, mcrypt, mysql, ereg,
aolserver, isapi, ...)
Remove the date.timezone warning
PHP7: What's new
● new operators
o Nullsafe Calls
function f($o) {
$o2 = $o->mayFail1();
if ($o2 === null) {
return null;
}
$o3 = $o2->mayFail2();
if ($o3 === null) {
return null;
}
$o4 = $o3->mayFail3();
if ($o4 === null) {
return null;
}
return $o4->mayFail4();
}
function f($o) {
return $o?->mayFail1()?->mayFail2()?->mayFail3()?->mayFail4();
}
PHP7: What's new
● new operators
o Spaceship
PHP7: What's new
operator <=> equivalent
$a < $b ($a <=> $b) === -1
$a <= $b ($a <=> $b) === -1 || ($a <=> $b) === 0
$a == $b ($a <=> $b) === 0
$a != $b ($a <=> $b) !== 0
$a >= $b ($a <=> $b) === 1 || ($a <=> $b) === 0
$a > $b ($a <=> $b) === 1
● new operators
o Null Coalesce
// Without null coalesce
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
// With null coalesce
$username = $_GET['user'] ?? 'nobody';
PHP7: What's new
● Context Sensitive Lexer
PHP7: What's new
Newly reserved Now possible
int Class::forEach()
float Class::list()
bool Class::for()
string Class::and()
true, false Class::or()
null Class::new()
Class::include()
const CONTINUE
● Anonymous class support
/* implementing an anonymous console object from your framework maybe */
(new class extends ConsoleProgram {
public function main() {
/* ... */
}
})->bootstrap();
class Foo {}
$child = new class extends Foo {};
var_dump($child instanceof Foo); // true
// New Hotness
$pusher->setLogger(new class {
public function log($msg) {
print_r($msg . "n");
}
});
PHP7: What's new
● Uniform Variable Syntax
// old meaning // new meaning
$$foo['bar']['baz'] ${$foo['bar']['baz']} ($$foo)['bar']['baz']
$foo->$bar['baz'] $foo->{$bar['baz']} ($foo->$bar)['baz']
$foo->$bar['baz']() $foo->{$bar['baz']}() ($foo->$bar)['baz']()
Foo::$bar['baz']() Foo::{$bar['baz']}() (Foo::$bar)['baz']()
// Before
global $$foo->bar;
// Instead use
global ${$foo->bar};
● Unicode Codepoint Escape Syntax
"U+202E" // String composed by U+ will now not be parsed as special characters
echo "u{1F602}"; // outputs 😂
● Instance class by reference not working anymore
$class = &new Class(); // Will now return a Parse error
PHP7: What's new
● Loop else
foreach ($array as $x) {
echo "Name: {$x->name}n";
} else {
echo "No records found!n";
}
● Named Parameters
// Using positional arguments:
htmlspecialchars($string, double_encode => false);
// Same as
htmlspecialchars($string, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
// non changing default value
htmlspecialchars($string, default, default, false);
PHP7: Proposed features/In draft
● Union Types: multi types
function (array|Traversable $in) {
foreach ($in as $value) {
echo $value, PHP_EOL;
}
}
● Enum types
enum RenewalAction {
Deny,
Approve
}
function other(RenewalAction $action): RenewalAction {
switch ($action) {
case RenewalAction::Approve:
return RenewalAction::Deny;
case RenewalAction::Deny:
return RenewalAction::Approve;
}
}
PHP7: Proposed features/In draft
PHPNG: Next Generation
● PHP8.0: 2020
● PHP9.0: 2025
PHP7: References
● PHP: rfc
● Etat des lieux et avenir de PHP
● En route pour PHP7

Mais conteúdo relacionado

Mais procurados

PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13
julien pauli
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
What's new in PHP 5.5
What's new in PHP 5.5What's new in PHP 5.5
What's new in PHP 5.5
Tom Corrigan
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objects
julien pauli
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 

Mais procurados (20)

Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHPDoctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5
 
What's new in PHP 5.5
What's new in PHP 5.5What's new in PHP 5.5
What's new in PHP 5.5
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
Codeigniter4の比較と検証
Codeigniter4の比較と検証Codeigniter4の比較と検証
Codeigniter4の比較と検証
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objects
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
web2py:Web development like a boss
web2py:Web development like a bossweb2py:Web development like a boss
web2py:Web development like a boss
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and co
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 

Semelhante a PHP7 Presentation

JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
jsmith92
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
Alexei Gorobets
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri Moth
 

Semelhante a PHP7 Presentation (20)

Php 5.6 From the Inside Out
Php 5.6 From the Inside OutPhp 5.6 From the Inside Out
Php 5.6 From the Inside Out
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
 
Php 5.6
Php 5.6Php 5.6
Php 5.6
 
PHP Versions Upgradation - What's New vs Old Version.pdf
PHP Versions Upgradation - What's New vs Old Version.pdfPHP Versions Upgradation - What's New vs Old Version.pdf
PHP Versions Upgradation - What's New vs Old Version.pdf
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 Verona
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Diving into HHVM Extensions (Brno PHP Conference 2015)
Diving into HHVM Extensions (Brno PHP Conference 2015)Diving into HHVM Extensions (Brno PHP Conference 2015)
Diving into HHVM Extensions (Brno PHP Conference 2015)
 
ElePHPant7 - Introduction to PHP7
ElePHPant7 - Introduction to PHP7ElePHPant7 - Introduction to PHP7
ElePHPant7 - Introduction to PHP7
 
Fatc
FatcFatc
Fatc
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
 
What's new with PHP7
What's new with PHP7What's new with PHP7
What's new with PHP7
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
DIG1108 Lesson 6
DIG1108 Lesson 6DIG1108 Lesson 6
DIG1108 Lesson 6
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

PHP7 Presentation

  • 2. Table of contents ● Preamble ● PHP5.6: in case you missed something a. Overview b. New features ● PHP7: future is coming a. Overview b. What's new
  • 3. Preamble ● Use filter_var() // Check valid email bool filter_var('example@site.tld', FILTER_VALIDATE_EMAIL); // Remove empty values $data = array( 'value1' => '', 'value2' => null, 'value3' => [] ); filter_var_array($data); // return empty array ● Speed the code DON'T open/close PHP tags for excessive. DON'T use GLOBALS
  • 4. ● release date: August 2014 ● PHP5: last branch release PHP5.6: Overview
  • 5. PHP5.6: New features ● Constant expressions const ONE = 1; // Scalar Expression in constant const TWO = ONE * 2; ● Variadic functions/Argument unpacking function myTools($name, ...$tools) { echo "Name:". $name.'<br />'; echo "My Tool Count:". count(tools); } myTools('Avinash', 'Eclipse'); myTools('Avinash', 'Eclipse', 'Sublime'); myTools('Avinash', 'Eclipse', 'Sublime', 'PHPStorm'); function myTools($name, $tool1, $tool2, $tool3) { echo "Name:". $name.'<br />'; echo "Tool1:", $tool1.'<br />'; echo "Tool2:", $tool2.'<br />'; echo "Tool3:", $tool3; } $myTools = ['Eclipse', 'Sublime', 'PHPStorm']; myTools('Avinash', ...$myTools);
  • 6. PHP5.6: New features ● Exponentiation // PHP5.5 and before pow(2, 8); // 256 // PHP5.6 and after echo 2 ** 8; // 256 echo 2 ** 2 ** 4; // 256 ● use function and use const namespace NameSpace { const FOO = 42; function f() { echo __FUNCTION__."n"; } } namespace { use const NameSpaceFOO; use function NameSpacef; echo FOO."n"; f(); }
  • 7. PHP5.6: New features ● phpdbg: The interactive debugger http://phpdbg.com/docs ● php://input // Now deprecated $HTTP_RAW_POST_DATA // This is now reusable file_get_contents('php://input'); ● Large file uploads Files larger than 2 gigabytes in size are now accepted.
  • 8. PHP5.6: New features ● __debugInfo() class C { private $prop; public function __construct($val) { $this->prop = $val; } public function __debugInfo() { return [ 'propSquared' => $this->prop ** 2, ]; } } var_dump(new C(42)); object(C)#1 (1) { ["propSquared"]=> int(1764) }
  • 9. ● Release date: October 2015 ● Engine: Zend v3 (32/64 bits) ● Performance: 25% to 70% faster ● Backward Incompatible Changes ● New Parser ● Tidy up old things ● Many new features PHP7: Overview
  • 10. ● Scalar Type Declarations // must be the first statement in a file. // If it appears anywhere else in the file it will generate a compiler error. declare(strict_types=1); // Available type hints int, float, string, bool // Examples function add(string $a, string $b): string { return $a + $b; } function add(int $a, int $b): int { return $a + $b; } function add(float $a, float $b): float { return $a + $b; } function add(bool $a, bool $b): bool { return $a + $b; } PHP7: What's new
  • 11. ● Group Use Declarations // PHP7 use FooLibraryBarBaz{ ClassA, ClassB, ClassC, ClassD as Fizbo }; // Before PHP7 use FooLibraryBarBazClassA; use FooLibraryBarBazClassB; use FooLibraryBarBazClassC; use FooLibraryBarBazClassD as Fizbo; ● switch.default.multiple Will raise E_COMPILE_ERROR when multiple default blocks are found in a switch statement. PHP7: What's new
  • 12. ● Alternative PHP tags removed <% // opening tag <%= // opening tag with echo %> // closing tag (<scripts+languages*=s*(php|"php"|'php')s*>)i // opening tag (</script>)i // closing tag ● Return Type Declarations // Returning array // Overriding a method that did not have a return type: function foo(): array { interface Comment {} return []; interface CommentsIterator extends Iterator { } function current(): Comment; } // Returning object interface A { static function make(): A; } class B implements A { static function make(): A { return new B(); } } PHP7: What's new
  • 13. ● Update json parser extension json extension has been replaced by jsond extension echo json_encode(10.0); // Output 10 echo json_encode(10.1); // Output 10.1 echo json_encode(10.0, JSON_PRESERVE_ZERO_FRACTION); // Output 10.0 echo json_encode(10.1, JSON_PRESERVE_ZERO_FRACTION); // Output 10.1 var_dump(json_decode(json_encode(10.0, JSON_PRESERVE_ZERO_FRACTION))); // Output double(10) var_dump(10.0 === json_decode(json_encode(10.0, JSON_PRESERVE_ZERO_FRACTION))); // Output bool(true) ● Removing old codes PHP4 constructor Removal of dead/unmaintained/deprecated SAPIs and extensions (imap, mcrypt, mysql, ereg, aolserver, isapi, ...) Remove the date.timezone warning PHP7: What's new
  • 14. ● new operators o Nullsafe Calls function f($o) { $o2 = $o->mayFail1(); if ($o2 === null) { return null; } $o3 = $o2->mayFail2(); if ($o3 === null) { return null; } $o4 = $o3->mayFail3(); if ($o4 === null) { return null; } return $o4->mayFail4(); } function f($o) { return $o?->mayFail1()?->mayFail2()?->mayFail3()?->mayFail4(); } PHP7: What's new
  • 15. ● new operators o Spaceship PHP7: What's new operator <=> equivalent $a < $b ($a <=> $b) === -1 $a <= $b ($a <=> $b) === -1 || ($a <=> $b) === 0 $a == $b ($a <=> $b) === 0 $a != $b ($a <=> $b) !== 0 $a >= $b ($a <=> $b) === 1 || ($a <=> $b) === 0 $a > $b ($a <=> $b) === 1
  • 16. ● new operators o Null Coalesce // Without null coalesce $username = isset($_GET['user']) ? $_GET['user'] : 'nobody'; // With null coalesce $username = $_GET['user'] ?? 'nobody'; PHP7: What's new
  • 17. ● Context Sensitive Lexer PHP7: What's new Newly reserved Now possible int Class::forEach() float Class::list() bool Class::for() string Class::and() true, false Class::or() null Class::new() Class::include() const CONTINUE
  • 18. ● Anonymous class support /* implementing an anonymous console object from your framework maybe */ (new class extends ConsoleProgram { public function main() { /* ... */ } })->bootstrap(); class Foo {} $child = new class extends Foo {}; var_dump($child instanceof Foo); // true // New Hotness $pusher->setLogger(new class { public function log($msg) { print_r($msg . "n"); } }); PHP7: What's new
  • 19. ● Uniform Variable Syntax // old meaning // new meaning $$foo['bar']['baz'] ${$foo['bar']['baz']} ($$foo)['bar']['baz'] $foo->$bar['baz'] $foo->{$bar['baz']} ($foo->$bar)['baz'] $foo->$bar['baz']() $foo->{$bar['baz']}() ($foo->$bar)['baz']() Foo::$bar['baz']() Foo::{$bar['baz']}() (Foo::$bar)['baz']() // Before global $$foo->bar; // Instead use global ${$foo->bar}; ● Unicode Codepoint Escape Syntax "U+202E" // String composed by U+ will now not be parsed as special characters echo "u{1F602}"; // outputs 😂 ● Instance class by reference not working anymore $class = &new Class(); // Will now return a Parse error PHP7: What's new
  • 20. ● Loop else foreach ($array as $x) { echo "Name: {$x->name}n"; } else { echo "No records found!n"; } ● Named Parameters // Using positional arguments: htmlspecialchars($string, double_encode => false); // Same as htmlspecialchars($string, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); // non changing default value htmlspecialchars($string, default, default, false); PHP7: Proposed features/In draft
  • 21. ● Union Types: multi types function (array|Traversable $in) { foreach ($in as $value) { echo $value, PHP_EOL; } } ● Enum types enum RenewalAction { Deny, Approve } function other(RenewalAction $action): RenewalAction { switch ($action) { case RenewalAction::Approve: return RenewalAction::Deny; case RenewalAction::Deny: return RenewalAction::Approve; } } PHP7: Proposed features/In draft
  • 22. PHPNG: Next Generation ● PHP8.0: 2020 ● PHP9.0: 2025
  • 23. PHP7: References ● PHP: rfc ● Etat des lieux et avenir de PHP ● En route pour PHP7