Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Talks #75 - PHP 7

Avatar for Mihai Nica Mihai Nica
November 11, 2015

Talks #75 - PHP 7

PHP7 it's almost ready. Let's do a quick review of the biggest PHP release since 5.3.

Avatar for Mihai Nica

Mihai Nica

November 11, 2015
Tweet

More Decks by Mihai Nica

Other Decks in Programming

Transcript

  1. PHP 7 Highlights • Scalar type declarations • Return type

    declarations • Null coalesce operator ?? • Combined comparison operator <=> • Anonymous classes • Way faster then previous release
  2. Scalar Typehints • bool, float, int, string • declare(strict_types=1) •

    function sum(int $a, int $b) {
 return $a + $b
 }
  3. Return type declarations • Same types as for argument type

    declarations • function sum(int $a, int $b):int {
 return $a + $b
 }
  4. Null coalesce operator
 ?? • Because we are lazy and

    other languages have it • $u = isset($_GET['user']) ? $_GET['user'] : 'nobody';
 
 becomes
 
 $u = $_GET['user'] ?? 'nobody';
  5. Combined comparison operator <=> • aka Spaceship operator • sorting

    the right way • echo 1 <=> 1; // 0
 echo 1 <=> 2; // -1
 echo 2 <=> 1; // 1
  6. Anonymous classes • Throwaway objects made easy • Testers rejoice

    • $app = new Application;
 $app->setLogger(new class implements Logger {
 public function log(string $msg) {
 echo $msg;
 }
 });
  7. 2X faster?! • PHP Framework Benchmark available on Github: http://rtr.im/y

    • Virtual machine (2 cores @ 3.4GHz, 4GB RAM) running Ubuntu 14.04 • nginx 1.6 + php-fpm
  8. FRAMEWORK REQUEST PER SECOND PHP 5.5.15 PHP 7 - RC7

    PHALCON-2.0 1469 6605 CI-3.0 314 918 LUMEN-5.1 223 1345 YII-2.0 189 363 SILEX-1.3 486 1822 AURA-2.0 257 1080 CAKE-3.1 174 472 SYMFONY-2.7 167 326 LARAVEL-5.1 80 72 ZF-2.5 40 445