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

PHP 7: What you need to know

Michael C.
September 05, 2015

PHP 7: What you need to know

Michael C.

September 05, 2015
Tweet

More Decks by Michael C.

Other Decks in Technology

Transcript

  1. michaelcullumuk void Cos(void) { Stack *s; char temp[64]; s =

    Pop(); if(!s) { Error("Stack error in cos"); return; } sprintf(temp,"%f",cos(s->douval)); Push(temp,DNUMBER); } <html><head><title>Cos Example</title></head> <body><h1>Cos Example</h1> <?echo Cos($input)> </body></html>
  2. michaelcullumuk •Gigabyte Z87X-UD3H i7-4771 4 cores @ 3.50GHz w/ 16G

    of Ram @ 1600MHz •Hyperthreading enabled for a total of 8 virtual cores •Toshiba THNSNHH256GBST SSD •Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.7- ckt9-2 (2015-04-13) x86_64 GNU/Linux •MySQL 5.6.24 •nginx-1.6.2 + php-fpm for all tests unless indicated otherwise •Quiet local 100Mbps network •siege benchmark tool run from a separate machine
  3. michaelcullumuk function getArray(): array { return 42; } getArray ();

    function get_config(): int { return 42; } get_config(); \TypeError Yay Return value of getArray() must // be of the type array, integer returned in %s on line %d
  4. michaelcullumuk function fooBar(string $foo, int $bar, float $test, int $Michael)

    { var_dump($foo); // string(1) "1" var_dump($bar); // int(2) var_dump($test); // float(3) var_dump($Michael); // int(1) } fooBar(1, "2.5", 3, “1 Michael", );
  5. michaelcullumuk <?php declare(strict_types=1); Namespace Phpbb/Sub/AwesomeClass; public function fooBar(string $foo, int

    $bar, float $test, int $Michael) { return $this; } fooBar(1, "2.5", 3, “1 Michael");
  6. michaelcullumuk <?php declare(strict_types=1); Namespace Phpbb/Sub/AwesomeClass; public function fooBar(string $foo, int

    $bar, float $test, int $Michael) { return $this; } fooBar(1, "2.5", 3, “1 Michael");
  7. michaelcullumuk class AnObject extends BaseObject { public function getInterface() {

    return new class implements MyInterface { /* ... */ }; } }
  8. michaelcullumuk echo $a ?? $b; // NULL echo $c ??

    $b; // 2 echo $a ?? $b ?? $c; // 2 echo $a ?? $x ?? $c; // 2 echo $var ?? $foo ?? $undeclared; // NULL $a = NULL; $b = NULL; $c = 2;
  9. michaelcullumuk function oldWay($a, $b) { return ($a < $b) ?

    -1 : (($a >$b) ? 1 : 0); } function newWay($a, $b) { return $a <=> $b; }
  10. michaelcullumuk Operator Equivalent with Flying Saucers! $a < $b ($a

    <=> $b) === -1 $a == $b ($a <=> $b) === 0 $a > $b ($a <=> $b) === 1 $a != $b ($a <=> $b) !== 0 $a <= $b ($a <=> $b) === -1 || ($a <=> $b) === 0 $a >= $b ($a <=> $b) === 1 || ($a <=> $b) === 0
  11. michaelcullumuk // Pre PHP 7 code use some\namespace\ClassA; use some\namespace\ClassB;

    use some\namespace\ClassC as C; use function some\namespace\fn_a; use function some\namespace\fn_b; use function some\namespace\fn_c; // PHP 7+ code use some\namespace\{ClassA, ClassB, ClassC as C}; use function some\namespace\{fn_a, fn_b, fn_c}; use const some\namespace\{ConstA, ConstB, ConstC}; use const some\namespace\ConstA; use const some\namespace\ConstB; use const some\namespace\ConstC;
  12. michaelcullumuk • bool • int • float • string •

    null • false • true • resource • object • mixed • numeric