2017-05-28 46 views
-3

我需要一個變量傳遞到承諾Guzzlephp承諾可變

<?php 
$var = 'test'; 
$client = new Client(); 
$request = new Request('POST', 'https://url/'); 
$promise = $client->sendAsync($request, $options)->then(function ($response) { 
    $echo $var; 
}); 
$promise->wait(); 
+0

'$回聲是$ var;'? – walther

回答

1

的回報這是不是一種選擇? `

<?php 

$var = 'test'; 
$client = new Client(); 
$request = new Request('POST', 'https://url/'); 
$promise = $client 
    ->sendAsync($request, $options) 
    ->then(
     function ($response) use ($var) { 
      echo $var; 
     } 
    ); 
$promise->wait(); 

`