function ClosureCreater(){$x =1;return function($fun=null) use(&$x){//値を参照で渡すecho "".$x++; $fun と $fun(); }; } $x = "hello world"; $test = ClosureCreater( ); $test(); $test(function(){ echo "クロージャ テスト 1"; }); $test(function(){ echo "クロージャ テスト 2"; }); $test(function( ) use($x){ echo "".$x;}); //関数を配列要素として保存します $x = 'outer param.'; $arr = array( ) ; $arr[] = function($str)use($x){ return $str.$x; }; echo $arr[0]('arr で楽しいことをテスト,'); arr ,outer param. ?> コードをコピー