菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
34
0

PHP7中Closure :: call的使用范例

原创
05/13 14:22
阅读数 83372
PHP 7Closure::call()闭包函数动态对象实例

描述:

public mixed Closure::call ( object $newthis [, mixed $... ] )

暂时将闭包绑定到newthis,并用任何给定的参数调用。

php7之前的示例:

<?php
class A {
    private $x = 1;
  }
// PHP 7 之前版本定义闭包函数代码
    $getXCB = function()
    {
    return $this->x;
    };
// 闭包函数绑定到类 A 上
$getX = $getXCB->bindTo(new A, 'A'); 
echo $getX();
print(PHP_EOL);

php7之后的示例:

<?php
class A {
    private $x = 1;
  }
   $getX = function() {
        return $this->x;
  };
  echo $getX->call(new A);
 ?>

推荐:php视频教程 php7教程

以上就是PHP7中Closure :: call的使用范例的详细内容,更多请关注其它相关文章!

发表评论

0/200
34 点赞
0 评论
收藏
为你推荐 换一批