//PHP5 $a = array(1, 2, 3);foreach ($a as $v){var_dump(current($a));} int(2) int(2) int(2) $a = array(1, 2, 3);$b=&$a;foreach ($a as $v){var_dump(current($a));} int(2) int(3) bool(false) $a = array(1, 2, 3);$b=$a;foreach ($a as $v){var_dump(current($a));} int(1) int(1) int(1) //PHP7:不再操作数据的内部指针了 $a = array(1, 2, 3);foreach ($a as $v){var_dump(current($a))} int(1) int(1) int(1) $a = array(1, 2, 3);$b=&$a;foreach ($a as $v){var_dump(current($a)) int(1) int(1) int(1) $a = array(1, 2, 3);$b=$a;foreach ($a as $v){var_dump(current($a))} int(1) int(1) int(1)
新增的几个操作符
//<=> - 比较两个数的大小【-1:前者小于后者,0:前者等于后者,1:前者大于后者】 echo 1 <=> 2;//-1 echo 1 <=> 1;//0 echo 1 <=> 0;//1 // ** - 【a的b次方】 echo 2 ** 3;//8 //?? - 三元运算符的改进 //php5 $_GET['name'] ? $_GET['name'] : '';//Notice: Undefined index: … //php7 $_GET['name'] ?? '' -> ''; //\u{xxxx} - Unicode字符的解析 echo "\u{4f60}";//你 echo "\u{65b0}";//新
返回类型的声明
function getInt() : int { return “test”; }; getInt(); //PHP5 #PHP Parse error: parse error, expecting '{'... //PHP7 #Fatal error:Uncaught TypeError: Return value of getInt() must be of the type integer, string returned
标量类型的声明
function getInt(int $num) : int { return $num; }; getInt(“test”); //PHP5 #PHP Catchable fatal error: Argument 1 passed to getInt() must be an instance of int, string given… //PHP7 #Fatal error: Uncaught TypeError: Argument 1 passed to getInt() must be of the type integer, string given…
核心错误可以通过异常捕获了
try { non_exists_func(); } catch(EngineException $e) { echo “Exception: {$e->getMessage();}\n”; } //这里用php7试了一下还是没法捕获,但是看鸟哥介绍说是可行的。。。 #Exception: Call to undefined function non_exists_func()
上下问敏感的词法分析
//PHP5 class Collection {public function foreach($arr) {}} #Parse error: parse error, expecting `"identifier (T_STRING)”'... //PHP7 class Collection { public function foreach($arr) {} public function in($arr){} public function where($condition){} public function order($condition){} } $collection = new Collection(); $collection->where()->in()->foreach()->order();
差不多了,基本上就把自己对php7的初步了解说完了,其中肯定有很多不对的、低级的错误,希望各位兄弟及时指正,我好改一下,做个笔记!嘿嘿!
您可能感兴趣的文章: