Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Php7 傳說中的第七隻大象

889 visualizaciones

Publicado el

簡介 PHP7 新特色,並重點提示 PHP7 向下相容以及無法相容的部分,同時回顧一下 PHP 各版本時程。

Publicado en: Software
  • Sé el primero en comentar

Php7 傳說中的第七隻大象

  1. 1. PHP 7 7 Bobo Chen
  2. 2. • PHP • PHP 7 • 7 • 7 • 7 PHP 7
  3. 3. • PHP • PHP 7 • 7 • 7 • 7 PHP 7
  4. 4. 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
  5. 5. 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
  6. 6. 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
  7. 7. • PHP • PHP 7 • 7 • 7 • 7 PHP 7
  8. 8. PHP 7 http://media1.santabanta.com/full2/Animals/Elephants/elephants-14a.jpg ! ! ...
  9. 9. PHP 7 • • • (?) • 2015/12/3 http://media1.santabanta.com/full2/Animals/Elephants/elephants-14a.jpg
  10. 10. http://www.zend.com/en/resources/php7_infographic
  11. 11. http://www.zend.com/en/resources/php7_infographic
  12. 12. PHP 7 https://www.facebook.com/jace.ju/
  13. 13. • PHP • PHP 7 • 7 • 7 • 7 PHP 7
  14. 14. 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
  15. 15. PHP7 • MAMP Pro ( Demo ) • phpbrew PHP by c9s • Laravel Homestead
  16. 16. ?? 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
  17. 17. <=> 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
  18. 18. <=> 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
  19. 19. Type Declarations • Scalar type declarations int string float bool 
 <?php
 
 function setAge(int $age)
 {
 
 }
 
 setAge('this is string.');
 
 setAge('30'); // integer
 PHP7
  20. 20. Type Declarations • Return type declarations <?php
 
 function getUser() : User
 {
 return [];
 } interface SomeInterface {
 public function getUser() : User;
 
 } PHP7
  21. 21. Type Declarations • Strict mode <?php
 declare(strict_types=1); // PHP 
 
 function setAge(int $age)
 {
 
 }
 
 setAge('this is string.');
 PHP7
  22. 22. use App{Person, Animal};
 use App{Person as P, Animal as A}; Group use declarations use AppPerson;
 use AppAnimal; // use PHP5 PHP7
  23. 23. • PHP • PHP 7 • 7 • 7 • 7 PHP 7
  24. 24. 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…
  25. 25. Octal Literals // 8 PHP truncated echo 0128; // 012 echo 01281122; // 012 PHP5 echo 0128; // PHP7 Parse error: Invalid numeric literal PHP7
  26. 26. 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
  27. 27. 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
  28. 28. • PHP • PHP 7 • 7 • 7 • 7 PHP 7 ... T_T
  29. 29. 7 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
  30. 30. One More Thing…
  31. 31. PHP 7.1 is upcoming
  32. 32. PHP 7 7 The End.

×