PHP 7
PHP 7
4developers, 11 April 2016
Michał Pipa
About me
Michał Pipa ( )
Software developer, trainer
Zend Certi ed Engineer
Free software enthusiast ( )
(#symfony-pl)
@michalpipa
Symfony
PHPers Silesia
Polish Symfony Community
PHP 7
phpng
Wait, what about
PHP 6?
PHP 6 was abandoned in March
2010
PHP 6 = PHP 5.3 + unicode
unicode = PHP 6 - PHP 5.3
PHP 7 vs. HHVM
Why not HHVM?
Deploying is not easy and slow
Compatibility
Incompatible extensions
Developed by single company
Is PHP 7 ready for
production use?
Who is using PHP
7?
Etsy
Badoo
PHP 7: Improved performance
and memory usage
PHP's new hashtable implementation
Internal value representation in PHP 7
PHP 7: Return Type Declarations
function foo(): array {
return [];
}
PHP 7: Scalar Type Declarations
<?php
declare(strict_types=1);
function add(int $a, int $b): int {
return $a + $b;
}
PHP 7: Scalar Type Declarations
type checking mode for parameter types depends on the le where
the function is called
type checking mode for return types depends on the le where the
function is de ned
PHP 7: Anonymous Classes
var_dump(new class($i) {
public function __construct($i) {
$this->i = $i;
}
});
PHP 7: Combined Comparison
(Spaceship) Operator: <=>
PHP 7: Uniform Variable Syntax
PHP 7: Null Coalesce Operator:
??
isset($_GET['user']) ? $_GET['user'] : 'nobody'
$_GET['mykey'] ?: ""
$_GET['user'] ?? 'nobody'
PHP 7: Easy User-land CSPRNG
$randomStr = random_bytes($length = 16);
$randomInt = random_int($min = 0, $max = 127);
PHP 7: Group Use Declarations
use DoctrineCommonCollectionsExprComparison;
use DoctrineCommonCollectionsExprValue;
use DoctrineCommonCollectionsExprCompositeExpression;
use DoctrineCommonCollectionsExpr{ Comparison, Value, CompositeExpression };
PHP 7: intdiv()
intdiv(int $numerator, int $divisor)
PHP 7: Removed PHP 4
Constructors
PHP 7: Reserve More Types in
PHP 7
PHP 7: Remove alternative PHP
tags
ASP tags
script tags
PHP 7: Remove the
date.timezone warning
PHP 7: Exceptions in the engine
Before: Fatal error: Call to a member function method() on a non-object
After: Fatal error: Uncaught exception 'EngineException' with message
'Call to a member function method() on a non-object'
PHP 7: Abstract syntax tree
Tools
php7mar
Phan
Exakat
Tuli
Online PHP & HHVM shell, execute code in 100+ di erent versions!
3v4l.org
PHP specification
Thank you
Questions?

[4developers2016] PHP 7 (Michał Pipa)

  • 1.
  • 2.
    PHP 7 4developers, 11April 2016 Michał Pipa
  • 3.
    About me Michał Pipa( ) Software developer, trainer Zend Certi ed Engineer Free software enthusiast ( ) (#symfony-pl) @michalpipa Symfony PHPers Silesia Polish Symfony Community
  • 4.
  • 5.
  • 6.
  • 7.
    PHP 6 wasabandoned in March 2010
  • 8.
    PHP 6 =PHP 5.3 + unicode
  • 9.
    unicode = PHP6 - PHP 5.3
  • 10.
  • 11.
    Why not HHVM? Deployingis not easy and slow Compatibility Incompatible extensions Developed by single company
  • 12.
    Is PHP 7ready for production use?
  • 13.
    Who is usingPHP 7? Etsy Badoo
  • 14.
    PHP 7: Improvedperformance and memory usage PHP's new hashtable implementation Internal value representation in PHP 7
  • 15.
    PHP 7: ReturnType Declarations function foo(): array { return []; }
  • 16.
    PHP 7: ScalarType Declarations <?php declare(strict_types=1); function add(int $a, int $b): int { return $a + $b; }
  • 17.
    PHP 7: ScalarType Declarations type checking mode for parameter types depends on the le where the function is called type checking mode for return types depends on the le where the function is de ned
  • 18.
    PHP 7: AnonymousClasses var_dump(new class($i) { public function __construct($i) { $this->i = $i; } });
  • 19.
    PHP 7: CombinedComparison (Spaceship) Operator: <=>
  • 20.
    PHP 7: UniformVariable Syntax
  • 21.
    PHP 7: NullCoalesce Operator: ?? isset($_GET['user']) ? $_GET['user'] : 'nobody' $_GET['mykey'] ?: "" $_GET['user'] ?? 'nobody'
  • 22.
    PHP 7: EasyUser-land CSPRNG $randomStr = random_bytes($length = 16); $randomInt = random_int($min = 0, $max = 127);
  • 23.
    PHP 7: GroupUse Declarations use DoctrineCommonCollectionsExprComparison; use DoctrineCommonCollectionsExprValue; use DoctrineCommonCollectionsExprCompositeExpression; use DoctrineCommonCollectionsExpr{ Comparison, Value, CompositeExpression };
  • 24.
    PHP 7: intdiv() intdiv(int$numerator, int $divisor)
  • 25.
    PHP 7: RemovedPHP 4 Constructors
  • 26.
    PHP 7: ReserveMore Types in PHP 7
  • 27.
    PHP 7: Removealternative PHP tags ASP tags script tags
  • 28.
    PHP 7: Removethe date.timezone warning
  • 29.
    PHP 7: Exceptionsin the engine Before: Fatal error: Call to a member function method() on a non-object After: Fatal error: Uncaught exception 'EngineException' with message 'Call to a member function method() on a non-object'
  • 30.
    PHP 7: Abstractsyntax tree
  • 31.
  • 32.
    Online PHP &HHVM shell, execute code in 100+ di erent versions! 3v4l.org
  • 33.
  • 34.
  • 35.