Example of using Closure::call in PHP7

autoload
Release: 2023-02-17 20:48:02
Original
1900 people have browsed it

PHP 7'sClosure::call()has better performance. Its function is to dynamically bind aclosure function to a new one.Object instanceAnd call and execute the function.

Description:

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

Temporarily binds the closure to

newthisand calls it with any given arguments.

Example before php7:

x; }; // 闭包函数绑定到类 A 上 $getX = $getXCB->bindTo(new A, 'A'); echo $getX(); print(PHP_EOL);
Copy after login

Example after php7:

x; }; echo $getX->call(new A); ?>
Copy after login

Recommended:

php video tutorialphp7 tutorial

The above is the detailed content of Example of using Closure::call in PHP7. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!