這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)closurez在php中的使用方法有哪些,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
Closure,匿名函數(shù),是php5.3的時(shí)候引入的,又稱為Anonymous functions。字面意思也就是沒(méi)有定義名字的函數(shù)。比如以下代碼(文件名是do.php)
<?php function A() { return 100; }; function B(Closure $callback) { return $callback(); } $a = B(A()); print_r($a);//輸出:Fatal error: Uncaught TypeError: Argument 1 passed to B() must be an instance of Closure, integer given, called in D:\web\test\do.php on line 11 and defined in D:\web\test\do.php:6 Stack trace: #0 D:\web\test\do.php(11): B(100) #1 {main} thrown in D:\web\test\do.php on line 6 ?>