我需要将一个变量传递给promise
<?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 :(得分:3)
这不是一个选择吗? `
<?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();
`