forked from Yi-Lyu/Migrating-from-PHP5.6.x-to-PHP7.0.x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yi Lv
committed
Aug 24, 2015
1 parent
4fe9ef7
commit f0c8953
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# PHP5.6.x版本迁移至7.0.x版本 | ||
## 新的特性 | ||
### 标量类型声明 | ||
标量类型声明有两种模式:强制(默认)模式、严格模式。下列类型的参数可以被运用(无论用强制模式还是严格模式):字符串(string)、整形(int)、浮点数(float)和布尔型(bool)。其他类型在PHP5中有支持:类名、接口、数组和可被调用的。 | ||
```PHP | ||
<?php | ||
// Coercive mode | ||
function sumOfInts(int ...$ints) | ||
{ | ||
return array_sum($ints); | ||
} | ||
|
||
var_dump(sumOfInts(2, '3', 4.1)); | ||
``` | ||
上述例子输出: | ||
```PHP | ||
int(9) | ||
``` | ||
当开启严格模式后,一个 [declare](http://php.net/manual/en/control-structures.declare.php) 声明必须置于PHP脚本文件开头,这意味着严格声明标量是基于文件可配的。这个指令不仅影响参数的类型声明,也影响到函数的返回值声明(详见下面的返回值声明)。<br> | ||
详细的标量类型声明的文档与示例,可以查看[类型声明](http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration)页面。 | ||
|