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

Wat is er nieuw in PHP 7 - FeWeb Summerevent 2016

Wat is er nieuw in PHP 7 - FeWeb Summerevent 2016

Pecha Kucha presentation about what's new in PHP 7. Delivered in Dutch at the FeWeb Summerevent 2016.

https://talks.feryn.eu/talks/160/wat-is-er-nieuw-in-php-7-feweb-summerevent-herentals

Thijs Feryn

June 23, 2016
Tweet

More Decks by Thijs Feryn

Other Decks in Technology

Transcript

  1. PHP 5.0: 2004 PHP 5.1: 2005 PHP 5.2: 2006 PHP

    5.3: 2009 PHP 5.4: 2012 PHP 5.5: 2013 PHP 5.6: 2014 PHP 7.0: 3 december 2015
  2. <?php /** * Scalar type declarations */ //declare(strict_types=1); function add(int

    $a, int $b) { return $a + $b; } var_dump(add(1,2)); var_dump(add("1","2"));
  3. <?php /** * Return type declarations */ //declare(strict_types=1); function add(int

    $a, int $b): int{ return (string)($a + $b); } var_dump(add(1,2));
  4. <?php /** * Anonymous classes */ $foo = new class

    { public function foo() { return "bar"; } }; var_dump($foo,$foo->foo());
  5. <?php function gen_one_to_three() { for ($i = 1; $i <=

    3; $i++) { yield $i; } } $generator = gen_one_to_three(); foreach ($generator as $value) { echo "$value\n"; }
  6. <?php /** * Generator delegation */ function gen() { yield

    1; yield 2; yield from gen2(); } function gen2() { yield 3; yield 4; } foreach (gen() as $val) { echo $val, PHP_EOL; }
  7. <?php /** * Space ship operator */ $array = [

    "1 <=> 1" => 1 <=> 1, "1 <=> 2" =>1 <=> 2, "2 <=> 1" => 2 <=> 1 ]; var_dump($array); array(3) { '1 <=> 1' => int(0) '1 <=> 2' => int(-1) '2 <=> 1' => int(1) } Output
  8. <?php /** * Throwable interface */ //Error as Throwable try

    { sqdf(); } catch (Throwable $t) { echo "Throwable: ".$t->getMessage().PHP_EOL; } //Exception as Throwable try { throw new Exception("Bla"); } catch (Throwable $t) { echo "Throwable: ".$t->getMessage().PHP_EOL; } //Error try { sqdf(); } catch (Error $e) { echo "Error: ".$e->getMessage().PHP_EOL; } catch (Exception $e) { echo "Exception: ".$e->getMessage().PHP_EOL; }
  9. <?php /** * Throwable interface */ //Exception try { throw

    new Exception("Bla"); } catch (Error $e) { echo "Error: ".$e->getMessage().PHP_EOL; } catch (Exception $e) { echo "Exception: ".$e->getMessage().PHP_EOL; } //Type error try { function add(int $a, int $b):int { return $a + $b; } echo add(array(), array()); } catch (TypeError $t) { echo "Type error: ".$t->getMessage().PHP_EOL; }
  10. ✓Voorzien op shared hosting ✓Installeerbaar op Cloud ✓Opgelet for BC

    breaks PHP 7 bij http://php.net/manual/ en/migration70.php