php7 闭包调用

早起的版本如 PHP5.6 ,绑定并调用闭包使用 bindTo,而PHP7 中 Closure :: call()方法具备更好的性能,废话很少说,php

较早的 PHP 示例:

<?php
class Person {
    private $name = '乔峰';
}
$getName = function() {
    return $this->name;
};

// Bind a clousure
$value = $getName->bindTo(new Person, 'Person');

print($value());// 乔峰

PHP7 示例:

<?php
class Person {
    private $name = '乔峰';
}

$getName = function() {
    return $this->name;
};

print($getName->call(new Person));//乔峰 注意 这里能够直接是 new person,固然new person()也能够
相关文章
相关标签/搜索