I have a setup like this:
function test(){
function(){
return "testing!";
};
return;
}
echo test();
And I'm trying to get the test()
function to return "testing" (in this example) but that doesn't work. What would you advice?
Why are you using an anonymouse function? I have to use an anonymous function for this because I'm using the HttpClient of ReactPHP, here's a basic example of how that works:
$request = $client->request('GET', 'https://api.github.com/repos/reactphp/react/commits');
$request->on('response', function ($response) {
$buffer = '';
$response->on('data', function ($data) use (&$buffer) {
$buffer .= $data;
echo ".";
});
$response->on('end', function () use (&$buffer) {
$decoded = json_decode($buffer, true);
$latest = $decoded[0]['commit'];
$author = $latest['author']['name'];
$date = date('F j, Y', strtotime($latest['author']['date']));
echo "\n";
echo "Latest commit on react was done by {$author} on {$date}\n";
echo "{$latest['message']}\n";
});
});
$request->on('end', function ($error, $response) {
echo $error;
});
$request->end();
In the example above they echo the content of the page, but I'd like to return it instead, any help would be much appreciated. Thanks!
$request
really work asynchronous? Might there be a situation, when calling script ends, before request is done? – CORRUPT May 29 at 3:54$request
? – CORRUPT May 29 at 4:05