// get_class() 函数不再接受 null var_dump(get_class(null)); // PHP72 // Warning: get_class() expects parameter 1 to be object // bool(false) // // PHP71 // Warning: get_class() called without object from outside a class // bool(false) // // PHP80 // Fatal error: Uncaught TypeError: get_class(): Argument #1 ($object) must be of type object, null given
// 计算非可数类型(non-countable)时发出警告 var_dump( count(null), // NULL is not countable count(1), // integers are not countable count('abc'), // strings are not countable count(new stdclass) // objects not implementing the Countableinterface are not countable ); // PHP72 // Warning: count(): Parameter must be an array or an object that implements Countable // // PHP71 // 无 Warning // // PHP80 // Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array
// Heredoc Nowdoc 不再需要后跟分号或换行符 // 结束标记可以缩进,结束时所引用的标识符必须在该行的第一列 $values = [<<<END a b c END, 'd e f']; var_dump($values); // PHP73 // array(2) { // [0]=> // string(13) "a // b // c" // [1]=> // string(5) "d e f" // } // // PHP72 // Parse error: syntax error, unexpected end of file
echo<<<END a b c END; // PHP73 // a // b // c // // PHP72 // Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN)
echo<<<END a b c END; // PHP73 // Parse error: Invalid body indentation level
// Gets the first key of an array array_key_first(array$array): int|string|null // Gets the last key of an array array_key_last(array$array): int|string|null // Get the system's high resolution time // [seconds, nanoseconds] int(64 位平台)或 float(32 位平台) hrtime(bool$as_number = false): array|int|float|false // 验证变量的内容是否为 countable 值 // return is_array($value) || $value instanceof Countable || $value instanceof ResourceBundle || $value instanceof SimpleXmlElement; is_countable(mixed$value): bool
Backward Incompatible Changes 7.3
// Continue Targeting Switch 问题警告 $foo = 0; while ($foo < 10) { switch ($foo) { case"baz": continue; } $foo++; } // PHP73 // Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? // // PHP72 // ok