Php7 傳說中的第七隻大象

Tags
My-slides
Date
Jul 12, 2016
https://www.slideshare.net/bobo52310/php7-63930069

Php7 傳說中的第七隻大象 [slides]

  1. PHP 7 Bobo Chen
  1. PHP 6 ? PHP Personal Home Page Tools 1.0 PHP/FI 2 PHP 3 PHP 4 PHP 5 PHP 7 1995 1997 1998 2000 2004 2015
  1. PHP 2013 2014 2015 2016 2017 2018 5.3 5.4 5.5 5.6 7.0 http://php.net/supported-versions.php 7/10 12/3 12/31 12/3 12/3 12/31 Active support Security fixes only
  1. PHP 5.3 Namespace Anonymous Functions ?: Fix bugs 5.4 Traits Array php -S localhost:8000 5.5 Generators ClassName::class try ... catch ... finally list() yield 5.6 Constant expressions ¶ Enhance use operator ** Variadic functions via ... ¶ 7.0
  1. PHP 7 http://media1.santabanta.com/full2/Animals/Elephants/elephants-14a.jpg ! ! ...
  1. PHP 7 • • • (?) • 2015/12/3 http://media1.santabanta.com/full2/Animals/Elephants/elephants-14a.jpg
  1. http://www.zend.com/en/resources/php7_infographic
  1. http://www.zend.com/en/resources/php7_infographic
  1. PHP 7 https://www.facebook.com/jace.ju/
  1. 7 1. The Null Coalesce Operator (??) 2. The Spaceship Operator (<=>) 3. Type Declarations 4. Anonymous Classes 5. Whitelisting Unserialization 6. Session Initialization Options 7. Group use declarations(Namespace use) and more… http://php.net/manual/en/migration70.new-features.php
  1. PHP7 • MAMP Pro ( Demo ) • phpbrew PHP by c9s • Laravel Homestead
  1. ?? Null Coalesce Operator // PHP 5 if (isset($_GET['user'])) { $user = $_GET['user']; } else { $user = 'Nobody'; } // PHP 5.3 $user = isset($_GET['user']) ? $_GET['user'] : 'Nobody'; PHP5 $user = $_GET['user'] ?? 'Nobody'; PHP7
  1. <=> Spaceship Operator echo 1 <=> 2; // -1 echo 1 <=> 1; // 0 echo 2 <=> 1; // 1 https://www.javacodegeeks.com/wp-content/uploads/2014/01/space-ship.jpeg PHP7
  1. <=> Spaceship Operator function comparison($a, $b) { if ($a == $b) { return 0; } return ($a < $b) ? -1 : 1; } PHP5 function comparison($a, $b) { return $a <=> $b; } PHP7
  1. Type Declarations • Scalar type declarations int string float bool <?php function setAge(int $age) { } setAge('this is string.'); setAge('30'); // integer PHP7
  1. Type Declarations • Return type declarations <?php function getUser() : User { return []; } interface SomeInterface { public function getUser() : User; } PHP7
  1. Type Declarations • Strict mode <?php declare(strict_types=1); // PHP function setAge(int $age) { } setAge('this is string.'); PHP7
  1. use App{Person, Animal}; use App{Person as P, Animal as A}; Group use declarations use AppPerson; use AppAnimal; // use PHP5 PHP7
  1. 7 1. Octal Literals 2. String Parsing 3. Division by Zero 4. Uniform Variable Syntax 5. list() Behavior 6. Error Handling // Many fatal errors converted to Exceptions 7. PHP4 style Constructors are not allowed http://php.net/manual/en/migration70.incompatible.php and more…
  1. Octal Literals // 8 PHP truncated echo 0128; // 012 echo 01281122; // 012 PHP5 echo 0128; // PHP7 Parse error: Invalid numeric literal PHP7
  1. String Parsing var_dump(is_numeric("0x01A")); // true var_dump('0x1A' + '0x01'); // 10 26+1 PHP5 var_dump(is_numeric("0x01A")); // false var_dump('0x1A' + '0x01'); // 0+0=0 PHP7
  1. Division by Zero var_dump(5/0); // bool(false) var_dump(0/0); // bool(false) var_dump(5%0); // bool(false) PHP5 var_dump(5/0); // float(INF) var_dump(0/0); // float(NAN) // JavaScript JS NaN var_dump(5%0); // DivisionByZeroError PHP7
  1. PHP7 1. Never Use PHP Close Tags At the End of A File 2. Never Pass By Reference If Not Required 3. mysql_functions Should Not Be Used ( mysqli_*) 4. ereg PCRE extension: preg_* ( PCRE extension: preg_*) 5. PHP4 Constructors Are Now Deprecated 6. Removed Extensions 7. Removed old and unsupported SAPIs
  1. One More Thing…
  1. PHP 7.1 is upcoming

Loading Comments...