Home > Article > Backend Development > An article to talk about the features of php5.6 [Summary]
This article will talk about the features of php5.6 (constants as default values of function parameters, variable function parameters, namespaces, etc.). If you need it, you can take a look. I hope it will be helpful to everyone!
Better constants
Allows the use of previously defined constants when defining constants Calculation:
const A = 2; const B = A + 1; class C { const STR = "hello"; const STR2 = self::STR + ", world"; }
Allow constants as function parameters Default value:
function func($arg = C::STR2)
Better variable function parameters
Used to replace func_get_args()
function add(...$args) { $result = 0; foreach($args as $arg) $result += $arg; return $result; }
At the same time, when calling the function, the array can be expanded into function parameters:
The code is as follows:
$arr = [2, 3]; add(1, ...$arr); // 结果为 6
Namespace
Namespace supports constants and functions:
namespace Name\Space { const FOO = 42; function f() { echo __FUNCTION__."\n"; } } namespace { use const Name\Space\FOO; use function Name\Space\f; echo FOO."\n"; f(); }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of An article to talk about the features of php5.6 [Summary]. For more information, please follow other related articles on the PHP Chinese website!