Upload
bobo52310
View
100
Download
0
Embed Size (px)
Citation preview
PHP 7 7
Bobo Chen
• PHP
• PHP 7
• 7
• 7
• 7 PHP 7
• PHP
• PHP 7
• 7
• 7
• 7 PHP 7
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
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
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
• PHP
• PHP 7
• 7
• 7
• 7 PHP 7
PHP 7
http://media1.santabanta.com/full2/Animals/Elephants/elephants-14a.jpg
!
!
...
PHP 7
•
•
• (?)
• 2015/12/3
http://media1.santabanta.com/full2/Animals/Elephants/elephants-14a.jpg
http://www.zend.com/en/resources/php7_infographic
http://www.zend.com/en/resources/php7_infographic
PHP 7
https://www.facebook.com/jace.ju/
• PHP
• PHP 7
• 7
• 7
• 7 PHP 7
71. 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
PHP7
• MAMP Pro ( Demo )
• phpbrew PHP by c9s
• Laravel Homestead
?? Null Coalesce Operator
// PHP 5if (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
<=> Spaceship Operator
echo 1 <=> 2; // -1 echo 1 <=> 1; // 0echo 2 <=> 1; // 1
https://www.javacodegeeks.com/wp-content/uploads/2014/01/space-ship.jpeg
PHP7
<=> 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
Type Declarations
• Scalar type declarations int string float bool
<?phpfunction setAge(int $age){}setAge('this is string.');setAge('30'); // integer
PHP7
Type Declarations
• Return type declarations
<?phpfunction getUser() : User{ return [];}
interface SomeInterface { public function getUser() : User;}
PHP7
Type Declarations
• Strict mode
<?phpdeclare(strict_types=1); // PHP function setAge(int $age){}setAge('this is string.');
PHP7
use App\{Person, Animal};use App\{Person as P, Animal as A};
Group use declarations
use App\Person;use App\Animal; // use
PHP5
PHP7
• PHP
• PHP 7
• 7
• 7
• 7 PHP 7
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…
Octal Literals
// 8 PHP truncated echo 0128; // 012echo 01281122; // 012
PHP5
echo 0128; // PHP7 Parse error: Invalid numeric literal
PHP7
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
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 NaNvar_dump(5%0); // DivisionByZeroError
PHP7
• PHP
• PHP 7
• 7
• 7
• 7 PHP 7 ... T_T
7 PHP71. 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
One More Thing…
PHP 7.1 is upcoming
PHP 7 7
The End.