Home > Backend Development > PHP Tutorial > An article to talk about the features of php5.6 [Summary]

An article to talk about the features of php5.6 [Summary]

青灯夜游
Release: 2023-04-11 07:10:01
forward
3330 people have browsed it

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!

An article to talk about the features of php5.6 [Summary]

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";
}
Copy after login

Allow constants as function parameters Default value:

function func($arg = C::STR2)
Copy after login

Better variable function parameters

Used to replace func_get_args()

function add(...$args)
{
    $result = 0;
    foreach($args as $arg)
        $result += $arg;
    return $result;
}
Copy after login

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
Copy after login

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();
}
Copy after login

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template