锟斤拷 PHP 7 锟叫o拷锟杰讹拷锟斤拷锟斤拷锟斤拷锟斤拷锟皆硷拷锟缴恢革拷锟斤拷锟斤拷锟斤拷锟斤拷锟襟,讹拷锟斤拷转锟斤拷为锟届常锟斤拷锟斤拷锟斤拷锟剿★拷 锟斤拷些锟届常锟教筹拷锟斤拷 Error 锟洁,锟斤拷锟斤拷实锟斤拷锟斤拷 Throwable 锟接匡拷 锟斤拷锟斤拷锟斤拷锟届常锟斤拷实锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷涌冢锟斤拷锟�
锟斤拷也锟斤拷味锟脚o拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟绞憋拷锟斤拷锟角帮拷锟斤拷锟斤拷械锟揭恍╋拷锟斤拷锟斤拷锟侥达拷锟诫将锟睫凤拷锟斤拷锟斤拷锟斤拷锟斤拷 锟斤拷为锟斤拷 PHP 7 锟芥本锟叫o拷锟窖撅拷使锟斤拷锟阶筹拷锟届常锟侥达拷锟斤拷锟斤拷锟斤拷锟斤拷恕锟� 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟矫伙拷胁锟斤拷锟� Error 锟届常锟斤拷锟斤拷么锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟襟)★拷
PHP 7 锟叫的达拷锟斤拷锟斤拷母锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟轿硷拷 PHP 7 锟斤拷锟斤拷锟斤拷锟斤拷 锟斤拷迁锟斤拷指锟斤拷锟斤拷要锟斤拷锟叫筹拷锟皆硷拷锟斤拷锟斤拷锟斤拷影锟斤拷谋锟斤拷锟斤拷
锟阶筹拷 Error 锟斤拷锟斤拷时锟斤拷锟斤拷锟� set_exception_handler() 锟斤拷锟斤拷斐o拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 Exception 锟斤拷锟斤拷锟结导锟斤拷 fatal error锟斤拷
锟斤拷要锟届常锟斤拷锟斤拷锟斤拷同时支锟斤拷 PHP5 锟斤拷 PHP7锟斤拷应锟斤拷删锟斤拷锟届常锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� PHP7锟斤拷锟斤拷锟斤拷园锟斤拷锟斤拷锟� Exception 锟芥换锟斤拷 Throwable锟斤拷
<?php
// PHP 5 时锟斤拷锟侥达拷锟诫将锟斤拷锟斤拷锟斤拷锟斤拷锟�
function handler(Exception $e) { ... }
set_exception_handler('handler');
// 锟斤拷锟斤拷 PHP 5 锟斤拷 7
function handler($e) { ... }
// 锟斤拷支锟斤拷 PHP 7
function handler(Throwable $e) { ... }
?>
锟斤拷之前锟芥本锟叫o拷锟斤拷锟斤拷诓锟斤拷锟侥癸拷锟斤拷锟斤拷锟斤拷锟斤拷锟结返锟斤拷 NULL
锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟矫的讹拷锟斤拷
锟斤拷 PHP 7 锟斤拷始锟斤拷锟斤拷锟斤拷诓锟斤拷喙癸拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�
锟斤拷么锟斤拷锟阶筹拷锟届常锟斤拷
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷壮锟� ParseError 锟届常锟斤拷 锟斤拷锟斤拷 eval() 锟斤拷锟斤拷锟斤拷锟斤拷要锟斤拷锟斤拷锟斤拷锟斤拷锟揭伙拷锟� catch 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
原锟叫碉拷 E_STRICT
锟斤拷锟芥都锟斤拷迁锟狡碉拷锟斤拷锟斤拷锟斤拷锟斤拷
E_STRICT
锟斤拷锟斤拷锟结被锟斤拷锟斤拷锟斤拷锟斤拷锟皆碉拷锟斤拷
error_reporting(E_ALL|E_STRICT) 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
锟斤拷锟斤拷 | 锟铰的硷拷锟斤拷/锟斤拷为 |
---|---|
锟斤拷锟斤拷源锟斤拷锟酵的憋拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 | E_NOTICE |
锟斤拷锟斤拷态锟斤拷锟斤拷 | 锟斤拷锟劫撅拷锟芥,锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 |
锟截革拷锟斤拷锟藉构锟斤拷锟斤拷锟斤拷锟斤拷 | 锟斤拷锟劫撅拷锟芥,锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 |
锟节继承碉拷时锟津,凤拷锟斤拷签锟斤拷锟斤拷匹锟斤拷 | E_WARNING |
锟斤拷锟斤拷锟斤拷 trait 锟叫帮拷锟斤拷锟斤拷同锟侥o拷锟斤拷锟捷的o拷锟斤拷锟斤拷 | 锟斤拷锟劫撅拷锟芥,锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 |
锟皆非撅拷态锟斤拷锟矫的凤拷式锟斤拷锟绞撅拷态锟斤拷锟斤拷 | E_NOTICE |
锟斤拷锟斤拷应锟斤拷锟斤拷锟斤拷锟矫的凤拷式锟斤拷值 | E_NOTICE |
锟斤拷锟斤拷应锟斤拷锟斤拷锟斤拷锟矫的凤拷式锟斤拷锟捷o拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟叫o拷 | E_NOTICE |
锟皆撅拷态锟斤拷式锟斤拷锟斤拷实锟斤拷锟斤拷锟斤拷 | E_DEPRECATED |
PHP 7 锟斤拷锟斤拷使锟斤拷锟剿筹拷锟斤拷锟斤法锟斤拷锟斤拷锟斤拷锟斤拷源锟斤拷锟诫。锟斤拷使锟斤拷锟斤拷锟斤拷锟斤拷锟街帮拷锟絇HP锟侥斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷实锟街的改斤拷锟斤拷锟斤拷实锟街★拷 锟斤拷锟斤拷锟斤拷一锟斤拷锟皆碉拷原锟斤拷锟斤拷锟斤拷一些锟斤拷锟斤拷锟斤拷锟接的变动锟斤拷锟斤拷锟斤拷些锟戒动锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟捷★拷 锟斤拷锟斤拷一锟斤拷锟叫斤拷锟斤拷细锟斤拷锟斤拷锟斤拷些锟斤拷锟接★拷
锟皆憋拷锟斤拷锟斤拷锟斤拷锟皆和凤拷锟斤拷锟侥硷拷拥锟斤拷锟斤拷锟斤拷诮锟斤拷细锟斤拷锟窖拷锟斤拷锟斤拷业锟剿筹拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街帮拷幕锟斤拷锟斤拷偶锟斤拷锟斤拷锟斤拷獍革拷锟斤拷锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷锟脚憋拷说锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟剿筹拷锟侥变化锟斤拷
锟斤拷锟绞� | PHP 5 锟侥斤拷锟斤拷锟斤拷式 | PHP 7 锟侥斤拷锟斤拷锟斤拷式 |
---|---|---|
$$foo['bar']['baz']
|
${$foo['bar']['baz']}
|
($$foo)['bar']['baz']
|
$foo->$bar['baz']
|
$foo->{$bar['baz']}
|
($foo->$bar)['baz']
|
$foo->$bar['baz']()
|
$foo->{$bar['baz']}()
|
($foo->$bar)['baz']()
|
Foo::$bar['baz']()
|
Foo::{$bar['baz']}()
|
(Foo::$bar)['baz']()
|
使锟斤拷锟剿旧的达拷锟揭碉拷锟斤拷慕锟斤拷锟剿筹拷锟侥达拷锟斤拷锟斤拷氡伙拷锟叫达拷锟斤拷锟饺凤拷锟绞癸拷么锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟剿筹拷颍ú渭锟斤拷媳锟斤拷屑锟揭伙拷校锟斤拷锟� 锟斤拷锟斤拷使锟矫达拷锟斤拷缺锟斤拷锟斤拷锟斤拷锟絇HP 7.x锟斤拷前锟斤拷锟斤拷锟斤拷裕锟斤拷直锟斤拷锟斤拷锟斤拷锟絇HP 5.x锟侥猴拷锟斤拷锟斤拷锟斤拷浴锟�
锟斤拷同锟斤拷影锟斤拷锟斤拷 global 锟截硷拷锟街★拷锟斤拷锟斤拷锟揭拷幕锟斤拷锟斤拷锟绞癸拷么锟斤拷锟斤拷锟斤拷锟侥o拷锟街帮拷锟斤拷锟轿拷锟�
<?php
function f() {
// Valid in PHP 5 only.
global $$foo->bar;
// Valid in PHP 5 and 7.
global ${$foo->bar};
}
?>
list() 锟斤拷锟节会按锟秸憋拷锟斤拷锟斤拷锟斤拷锟剿筹拷锟斤拷锟斤拷锟斤拷锟斤拷墙锟斤拷懈锟街碉拷锟斤拷锟斤拷欠锟斤拷锟斤拷锟斤拷锟剿筹拷锟�
通锟斤拷锟斤拷说锟斤拷锟斤拷只锟斤拷影锟斤拷list() 锟斤拷锟斤拷锟斤拷锟�[]
锟斤拷锟斤拷锟斤拷一锟斤拷使锟矫的帮拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷示锟斤拷
<?php
list($a[], $a[], $a[]) = [1, 2, 3];
var_dump($a);
?>
Output of the above example in PHP 5:
array(3) { [0]=> int(3) [1]=> int(2) [2]=> int(1) }
Output of the above example in PHP 7:
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
锟斤拷之锟斤拷锟斤拷锟斤拷锟狡硷拷锟斤拷要锟斤拷锟斤拷list()锟侥革拷值顺锟斤拷锟斤拷为锟斤拷锟斤拷一锟斤拷锟斤拷未锟斤拷也锟斤拷锟斤拷锟斤拷锟绞碉拷锟较革拷凇锟�
list() 锟结构锟斤拷锟节诧拷锟斤拷锟斤拷锟角空的★拷锟斤拷锟铰碉拷锟斤拷锟接诧拷锟劫憋拷锟斤拷锟斤拷
<?php
list() = $a;
list(,,) = $a;
list($x, list(), $y) = $a;
?>
list() 锟斤拷锟斤拷锟杰解开锟街凤拷锟斤拷锟斤拷string锟斤拷锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷锟绞癸拷锟�str_split()锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
The order of the elements in an array has changed when those elements have been automatically created by referencing them in a by reference assignment. For example:
<?php
$array = [];
$array["a"] =& $array["b"];
$array["b"] = 1;
var_dump($array);
?>
Output of the above example in PHP 5:
array(2) { ["b"]=> &int(1) ["a"]=> &int(1) }
Output of the above example in PHP 7:
array(2) { ["a"]=> &int(1) ["b"]=> &int(1) }
锟斤拷 PHP 5锟叫o拷锟斤拷锟斤拷锟斤拷锟矫凤拷式锟斤拷锟捷猴拷锟斤拷锟斤拷锟斤拷时锟斤拷使锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷哦钥锟斤拷锟斤拷锟斤拷锟斤拷细锟斤拷准 锟侥撅拷锟芥。锟斤拷锟节o拷锟斤拷锟斤拷锟斤拷锟斤拷芑岽ワ拷锟斤拷锟�
<?php
function getArray() {
return [1, 2, 3];
}
function squareArray(array &$a) {
foreach ($a as &$v) {
$v **= 2;
}
}
// Generates a warning in PHP 7.
squareArray((getArray()));
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
Notice: Only variables should be passed by reference in /tmp/test.php on line 13
foreach锟斤拷锟斤拷锟斤拷细微锟侥变化锟斤拷锟斤拷锟狡结构锟斤拷 锟斤拷要围锟斤拷锟斤拷锟叫碉拷锟节诧拷锟斤拷锟斤拷指锟斤拷偷锟斤拷锟斤拷锟斤拷锟斤拷锟睫改★拷
锟斤拷PHP7之前锟斤拷锟斤拷锟斤拷锟斤拷通锟斤拷 foreach 锟斤拷锟斤拷时锟斤拷锟斤拷锟斤拷指锟斤拷锟斤拷贫锟斤拷锟斤拷锟斤拷诳锟绞硷拷锟斤拷锟斤拷锟斤拷锟剿o拷锟斤拷锟斤拷锟斤拷锟斤拷锟�
<?php
$array = [0, 1, 2];
foreach ($array as &$val) {
var_dump(current($array));
}
?>
Output of the above example in PHP 5:
int(1) int(2) bool(false)
Output of the above example in PHP 7:
int(0) int(0) int(0)
锟斤拷默锟斤拷使锟斤拷通锟斤拷值锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷foreach 实锟绞诧拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷牡锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷楸撅拷锟斤拷锟斤拷锟斤拷味锟脚o拷foreach 锟叫的诧拷锟斤拷锟斤拷锟斤拷锟睫革拷原锟斤拷锟斤拷锟街碉拷锟�
锟斤拷使锟斤拷锟斤拷锟矫憋拷锟斤拷锟斤拷锟斤拷时锟斤拷锟斤拷锟斤拷 foreach 锟节碉拷锟斤拷锟斤拷锟杰革拷锟矫的革拷锟劫变化锟斤拷锟斤拷锟界,锟节碉拷锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟街碉拷锟斤拷锟斤拷锟斤拷校锟斤拷慰锟斤拷锟斤拷锟侥达拷锟诫:
<?php
$array = [0];
foreach ($array as &$val) {
var_dump($val);
$array[1] = 1;
}
?>
Output of the above example in PHP 5:
int(0)
Output of the above example in PHP 7:
int(0) int(1)
锟斤拷锟斤拷一锟斤拷锟斤拷Traversable锟斤拷锟襟将伙拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为锟斤拷同锟斤拷 锟解将锟斤拷锟斤拷锟节讹拷锟斤拷锟斤拷踊锟缴撅拷锟斤拷锟斤拷锟绞憋拷锟�foreach通锟斤拷锟斤拷锟矫憋拷锟斤拷时锟斤拷锟叫革拷锟矫的碉拷锟斤拷锟斤拷锟斤拷也锟杰憋拷应锟斤拷
锟斤拷之前锟斤拷一锟斤拷锟剿斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟叫э拷锟斤拷郑锟斤拷锟斤拷锟叫э拷锟斤拷纸锟斤拷锟斤拷锟侥撅拷锟�(0128 锟斤拷锟斤拷锟斤拷锟斤拷为 012). 锟斤拷锟斤拷锟斤拷锟斤拷锟侥八斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
锟皆革拷锟斤拷锟斤拷式锟斤拷锟叫碉拷位锟斤拷锟斤拷锟姐将锟斤拷锟阶筹拷一锟斤拷 ArithmeticError锟斤拷
<?php
var_dump(1 >> -1);
?>
Output of the above example in PHP 5:
int(0)
Output of the above example in PHP 7:
Fatal error: Uncaught ArithmeticError: Bit shift by negative number in /tmp/test.php:2 Stack trace: #0 {main} thrown in /tmp/test.php on line 2
锟斤拷锟斤拷 integer 位锟斤拷锟轿伙拷撇锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷母锟斤拷锟斤拷颍┙锟绞硷拷盏玫锟� 0 锟斤拷为锟斤拷锟斤拷锟斤拷诖锟角帮拷锟斤拷锟揭伙拷锟斤拷锟斤拷墙峁癸拷锟斤拷锟斤拷摹锟�
锟斤拷十锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟劫憋拷锟斤拷为锟斤拷锟斤拷锟街★拷锟斤拷锟界:
<?php
var_dump("0x123" == "291");
var_dump(is_numeric("0x123"));
var_dump("0xe" + "0x1");
var_dump(substr("foo", "0x1"));
?>
Output of the above example in PHP 5:
bool(true) bool(true) int(15) string(2) "oo"
Output of the above example in PHP 7:
bool(false) bool(false) int(0) Notice: A non well formed numeric value encountered in /tmp/test.php on line 5 string(3) "foo"
filter_var() 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟节硷拷锟揭伙拷锟� string 锟角凤拷锟斤拷十锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷,锟斤拷锟斤拷锟斤拷转锟斤拷为integer:
<?php
$str = "0xffff";
$int = filter_var($str, FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX);
if (false === $int) {
throw new Exception("Invalid integer!");
}
var_dump($int); // int(65535)
?>
锟斤拷锟斤拷锟铰碉拷 Unicode codepoint escape syntax锟斤法锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷效锟斤拷锟叫诧拷锟斤拷锟斤拷\u{ 锟斤拷锟街达拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 为锟剿憋拷锟斤拷锟斤拷一锟斤拷锟斤拷应锟矫憋拷锟解反斜锟杰匡拷头锟斤拷
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷PHP 4.1.0锟斤拷始锟斤拷锟斤拷锟斤拷锟斤拷应锟斤拷使锟斤拷call_user_func() 锟斤拷 call_user_func_array()锟斤拷 锟斤拷也锟斤拷锟皆匡拷锟斤拷使锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷 ... 锟斤拷锟斤拷锟斤拷锟斤拷
锟窖凤拷锟斤拷锟斤拷 mcrypt_generic_end() 锟斤拷锟斤拷锟窖憋拷锟狡筹拷锟斤拷锟斤拷使锟斤拷mcrypt_generic_deinit()锟斤拷锟芥。
锟斤拷锟解,锟窖凤拷锟斤拷锟斤拷 mcrypt_ecb(),
mcrypt_cbc(), mcrypt_cfb() 锟斤拷
mcrypt_ofb() 锟斤拷锟斤拷锟窖憋拷锟狡筹拷锟斤拷锟斤拷锟斤拷锟角★拷锟斤拷锟�MCRYPT_MODE_*
锟斤拷锟斤拷锟斤拷使锟斤拷 mcrypt_decrypt()锟斤拷锟叫达拷锟芥。
锟斤拷锟斤拷 ext/mysql 锟斤拷锟斤拷锟窖憋拷删锟斤拷锟剿★拷 锟斤拷锟窖★拷锟酵拷锟� MySQL API锟斤拷锟斤拷锟斤拷锟斤拷锟� 选锟斤拷 MySQL API锟斤拷
锟斤拷锟斤拷 ext/mssql 锟斤拷锟斤拷锟窖憋拷删锟斤拷锟剿★拷 锟斤拷锟狡凤拷锟斤拷斜锟斤拷渭锟� MSSQL 锟斤拷锟斤拷锟斤拷
锟窖凤拷锟斤拷锟斤拷 datefmt_set_timezone_id() 锟斤拷 IntlDateFormatter::setTimeZoneID() 锟斤拷锟斤拷锟窖憋拷锟狡筹拷锟斤拷锟斤拷使锟斤拷 datefmt_set_timezone() 锟斤拷 IntlDateFormatter::setTimeZone()锟斤拷锟芥。
set_magic_quotes_runtime(), 锟斤拷锟斤拷锟侥憋拷锟斤拷 magic_quotes_runtime()锟窖憋拷锟狡筹拷. 锟斤拷锟斤拷锟斤拷PHP 5.3.0锟斤拷锟窖撅拷锟斤拷锟斤拷锟斤拷,锟斤拷锟斤拷 锟斤拷in PHP 5.4.0也锟斤拷锟斤拷魔锟斤拷锟斤拷锟脚的凤拷锟斤拷锟斤拷失去锟斤拷锟杰★拷
锟窖凤拷锟斤拷锟斤拷 set_socket_blocking() 锟斤拷锟斤拷锟窖憋拷锟狡筹拷锟斤拷锟斤拷使锟斤拷stream_set_blocking()锟斤拷锟芥。
Support for PostScript Type1 fonts has been removed from the GD extension, resulting in the removal of the following functions:
锟狡硷拷使锟斤拷 TrueType 锟斤拷锟斤拷锟斤拷锟截的猴拷锟斤拷锟斤拷为锟斤拷锟斤拷锟�
锟斤拷锟斤拷 INI 锟斤拷锟斤拷指锟斤拷锟窖撅拷锟斤拷锟狡筹拷锟斤拷同时锟狡筹拷锟侥伙拷锟斤拷锟斤拷锟接︼拷墓锟斤拷锟�
xsl.security_prefs
xsl.security_prefs
指锟筋被锟狡筹拷
锟斤拷预锟斤拷锟斤拷锟绞憋拷锟饺★拷锟斤拷锟街拷姆锟斤拷锟� XsltProcessor::setSecurityPrefs()
应锟矫憋拷锟斤拷锟矫碉拷
new 锟斤拷浯达拷锟斤拷亩锟斤拷锟斤拷锟� 锟斤拷锟斤拷锟矫的凤拷式锟斤拷值锟斤拷锟斤拷锟斤拷锟斤拷
<?php
class C {}
$c =& new C;
?>
Output of the above example in PHP 5:
Deprecated: Assigning the return value of new by reference is deprecated in /tmp/test.php on line 3
Output of the above example in PHP 7:
Parse error: syntax error, unexpected 'new' (T_NEW) in /tmp/test.php on line 3
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟洁、锟接匡拷锟皆硷拷 trait锟斤拷
锟斤拷锟解,也锟斤拷要使锟斤拷锟斤拷锟叫碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟洁、锟接匡拷锟皆硷拷 trait锟斤拷锟斤拷然锟斤拷 PHP 7.0 锟叫o拷 锟解并锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷些锟斤拷锟斤拷锟角憋拷锟斤拷锟斤拷锟斤拷锟斤拷使锟矫的★拷
使锟斤拷锟斤拷锟斤拷 ASP 锟侥憋拷签锟斤拷锟皆硷拷 script 锟斤拷签锟斤拷锟斤拷锟斤拷 PHP 锟斤拷锟斤拷姆锟绞斤拷锟斤拷瞥锟斤拷锟� 锟杰碉拷影锟斤拷谋锟角╋拷校锟�
锟斤拷锟斤拷签 | 锟秸憋拷签 |
---|---|
<% |
%> |
<%= |
%> |
<script language="php"> |
</script> |
锟节诧拷匹锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷跃锟教拷锟绞斤拷锟斤拷梅蔷锟教拷锟斤拷锟斤拷锟� 锟斤拷 PHP 5.6 锟斤拷锟窖撅拷锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷 PHP 7.0 锟叫o拷 锟结导锟铰憋拷锟斤拷锟矫凤拷锟斤拷锟斤拷未锟斤拷锟斤拷 $this 锟斤拷锟斤拷锟斤拷锟皆硷拷锟斤拷锟斤拷为锟窖撅拷锟斤拷锟斤拷锟侥撅拷锟芥。
<?php
class A {
public function test() { var_dump($this); }
}
// 注锟解:锟斤拷没锟叫达拷锟斤拷 A 锟教筹拷
class B {
public function callNonStaticMethodOfA() { A::test(); }
}
(new B)->callNonStaticMethodOfA();
?>
Output of the above example in PHP 5.6:
Deprecated: Non-static method A::test() should not be called statically, assuming $this from incompatible context in /tmp/test.php on line 8 object(B)#1 (0) { }
Output of the above example in PHP 7:
Deprecated: Non-static method A::test() should not be called statically in /tmp/test.php on line 8 Notice: Undefined variable: this in /tmp/test.php on line 3 NULL
锟斤拷使锟斤拷 yield 锟截硷拷锟街碉拷时锟津,诧拷锟斤拷锟斤拷要锟斤拷锟脚o拷 锟斤拷锟斤拷锟斤拷锟斤拷锟轿拷锟斤拷锟斤拷硬锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟饺硷拷锟斤拷锟斤拷 print 锟斤拷 => 之锟戒。 锟斤拷锟斤拷艿锟斤拷锟斤拷锟斤拷写锟斤拷锟斤拷锟斤拷为锟斤拷锟斤拷锟侥变:
<?php
echo yield -1;
// 锟斤拷之前锟芥本锟叫会被锟斤拷锟斤拷为锟斤拷
echo (yield) - 1;
// 锟斤拷锟节o拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为锟斤拷
echo yield (-1);
yield $foo or die;
// 锟斤拷之前锟芥本锟叫会被锟斤拷锟斤拷为锟斤拷
yield ($foo or die);
// 锟斤拷锟节o拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为锟斤拷
(yield $foo) or die;
?>
锟斤拷锟斤拷通锟斤拷使锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟藉。
锟节猴拷锟斤拷锟斤拷锟斤拷锟叫o拷锟斤拷锟斤拷锟皆帮拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷同锟斤拷锟侥诧拷锟斤拷锟斤拷
锟斤拷锟界,锟斤拷锟斤拷锟斤拷锟斤拷械暮锟斤拷锟斤拷锟斤拷锟结触锟斤拷
E_COMPILE_ERROR
锟斤拷锟斤拷
<?php
function foo($a, $b, $unused, $unused) {
//
}
?>
锟斤拷 switch 锟斤拷锟斤拷校锟斤拷锟斤拷锟斤拷锟斤拷叨锟斤拷 default 锟斤拷拇锟斤拷锟斤拷丫锟斤拷锟斤拷俦锟街э拷帧锟�
锟斤拷锟界,锟斤拷锟斤拷锟斤拷锟斤拷械锟� switch 锟斤拷锟结触锟斤拷
E_COMPILE_ERROR
锟斤拷锟斤拷
<?php
switch (1) {
default:
break;
default:
break;
}
?>
锟斤拷锟节猴拷锟斤拷锟斤拷锟斤拷锟斤拷使锟斤拷 func_get_arg() 锟斤拷 func_get_args() 锟斤拷锟斤拷锟斤拷锟斤拷锟接诧拷锟斤拷值锟斤拷 锟斤拷锟斤拷使锟斤拷 debug_backtrace() 锟斤拷锟斤拷锟介看锟斤拷锟捷革拷锟劫o拷 锟皆硷拷锟斤拷锟届常锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷牟锟斤拷锟街碉拷锟街革拷锟斤拷锟斤拷锟角帮拷锟街碉拷锟斤拷锌锟斤拷锟斤拷锟斤拷丫锟斤拷锟斤拷锟斤拷锟斤拷诘拇锟斤拷锟侥憋拷锟斤拷锟街碉拷锟斤拷锟� 锟斤拷锟斤拷锟斤拷锟角诧拷锟斤拷锟斤拷锟斤拷锟诫函锟斤拷时锟斤拷锟皆贾碉拷恕锟�
<?php
function foo($x) {
$x++;
var_dump(func_get_arg(0));
}
foo(1);?>
Output of the above example in PHP 5:
1
Output of the above example in PHP 7:
2
锟斤拷锟斤拷锟结供 $HTTP_RAW_POST_DATA 锟斤拷锟斤拷锟斤拷 锟斤拷使锟斤拷 php://input 锟斤拷为锟斤拷锟斤拷锟�
锟斤拷 INI 锟侥硷拷锟叫o拷锟斤拷锟斤拷支锟斤拷锟斤拷 # 锟斤拷始锟斤拷注锟斤拷锟叫o拷 锟斤拷使锟斤拷 ;锟斤拷锟街号o拷锟斤拷锟斤拷示注锟酵★拷 锟剿憋拷锟斤拷锟斤拷锟斤拷锟� php.ini 锟皆硷拷锟斤拷 parse_ini_file() 锟斤拷 parse_ini_string() 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷募锟斤拷锟�
JSON 锟斤拷展锟窖撅拷锟斤拷 JSOND 锟斤拷展取锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷值锟侥达拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷要注锟斤拷模锟� 锟斤拷一锟斤拷锟斤拷值锟斤拷锟斤拷锟皆碉拷牛锟�.锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷锟界,锟斤拷值 34. 锟斤拷锟斤拷写锟斤拷 34.0 锟斤拷 34锟斤拷锟斤拷 锟节讹拷锟斤拷锟斤拷锟绞癸拷每锟窖э拷锟斤拷锟斤拷锟斤拷锟绞撅拷锟街碉拷锟�e 前锟斤拷锟斤拷氩伙拷堑锟脚o拷.锟斤拷 锟斤拷锟斤拷锟界,3.e3 锟斤拷锟斤拷写锟斤拷 3.0e3 锟斤拷 3e3锟斤拷锟斤拷 锟斤拷锟解,锟斤拷锟街凤拷锟斤拷锟斤拷锟劫憋拷锟斤拷锟斤拷锟斤拷效锟斤拷 JSON 锟街凤拷锟斤拷锟斤拷
锟斤拷锟斤拷锟斤拷锟斤拷转锟斤拷为锟斤拷锟斤拷锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街堤拷螅锟斤拷锟斤拷薹锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟铰o拷
锟斤拷之前锟侥版本锟叫o拷锟节诧拷锟斤拷锟斤拷锟斤拷直锟接斤拷锟斤拷锟斤拷锟截断o拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
锟斤拷 PHP 7.0 锟叫o拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 E_WARNING 锟斤拷锟襟,诧拷锟揭凤拷锟斤拷 NULL
锟斤拷
锟斤拷锟皆讹拷锟斤拷峄帮拷锟斤拷锟斤拷锟斤拷校锟斤拷锟斤拷锟斤拷锟斤拷锟侥凤拷锟斤拷值锟斤拷锟斤拷 FALSE
锟斤拷也锟斤拷锟斤拷 -1锟斤拷
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟节o拷锟斤拷锟斤拷锟叫╋拷锟斤拷锟斤拷姆锟斤拷锟街碉拷锟斤拷遣锟斤拷锟街碉拷锟揭诧拷锟斤拷锟� -1
锟斤拷锟斤拷 0锟斤拷锟斤拷锟斤拷锟斤拷锟矫斤拷锟斤拷锟斤拷锟斤拷锟轿э拷埽锟斤拷锟斤拷锟斤拷锟斤拷锟� E_WARNING 锟斤拷锟斤拷
锟斤拷锟斤拷锟节诧拷锟斤拷锟斤拷锟姐法锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 锟斤拷锟杰会导锟铰对憋拷时锟斤拷锟斤拷为锟斤拷鹊亩锟斤拷元锟斤拷之锟斤拷锟剿筹拷锟斤拷榷锟斤拷锟�
Note:
锟节对憋拷时锟斤拷锟斤拷为锟斤拷鹊亩锟斤拷元锟斤拷之锟斤拷锟斤拷锟斤拷锟剿筹拷锟斤拷遣锟斤拷锟斤拷锟斤拷锟斤拷模锟斤拷锟绞癸拷锟斤拷锟饺碉拷锟斤拷锟斤拷元锟截o拷 锟斤拷锟角碉拷位锟斤拷也锟斤拷锟杰憋拷锟斤拷锟斤拷锟姐法锟斤拷锟侥变。
Mhash 锟斤拷展锟窖撅拷锟斤拷锟斤拷全锟斤拷锟较斤拷 Hash 锟斤拷展锟剿★拷 锟斤拷耍锟斤拷锟揭拷锟绞癸拷锟� extension_loaded() 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷欠锟街э拷锟� MHash 锟斤拷展锟剿o拷 锟斤拷锟斤拷使锟斤拷 function_exists() 锟斤拷锟斤拷锟斤拷锟斤拷锟叫硷拷狻� 锟斤拷锟解,锟斤拷锟斤拷 get_loaded_extensions() 锟皆硷拷锟斤拷氐锟斤拷锟斤拷锟斤拷校锟揭诧拷锟斤拷俦锟斤拷锟� 锟斤拷 MHash 锟斤拷展锟斤拷氐锟斤拷锟较拷恕锟�