当我调用此函数时,它不会返回数据(单独使用 return),但是当我使用 print_r 时它可以工作。
这是connector.php
class Connector
{
public function Connect() {
$client = new Client(null);
$cookiePlugin = new CookiePlugin(new ArrayCookieJar());
$client->addSubscriber($cookiePlugin);
private $MainPageURL = "http://example.com";
$login_url = $this->GetMainPage($client, $this->MainPageURL);
}
private function GetMainPage($client, $url) {
$request = $client->get($url);
$response = $request->send();
$data = $response->getInfo('url');
return $data; // doesn't work
print_r($data); //works
}
}
和 client.php 包含
require 'connector.php';
$connector = new Connector($datos);
$con = $connector->Connect();
echo $con["login_url"];