I am absolutly new in PHP (I came from Java that is strongly typed) and I am going crazy trying to understand why I can't convert into a string this object and some object concept in PHP.
So I have this code doLogin() method (into a Laravel controller class):
public function doLogin(){
$userName = Input::get('username');
$pswd = Input::get('password');
//------------------------------------------
// Guzzle clint used to perform REST call:
//------------------------------------------
$client = new Client(); //GuzzleHttp\Client
//----------------------------------------------------------------------------------------------
// Do the REST call and obain the response:
//----------------------------------------------------------------------------------------------
$response = $client->get('http://localhost:8080/Accomodation/7');
// Decode the response into an object:
$dettaglioHotel = json_decode($response->getBody());
//Console::info('username: ' + $userName);
//Console::info('password ' + $pswd);
\Log::info('username: '.$userName);
\Log::info('password '.$pswd);
//\Log::info('hotel: '.$dettaglioHotel);
\Log::info('response status code: '.(string)$response->getStatusCode());
\Log::info('response: '.(string)$dettaglioHotel);
return view('dashboard-hotel');
}
So as you can see in the previus method I am using Guzzle library to perform a REST call.
My doubts are:
1) Into PhpStorm (the used IDE), passing the mouse on the get() method it say to me that the returned object have type ResponseInterface that is an interface and not a concrete class type.
So what exactly means? That doing:
$response = $client->get('http://localhost/Accomodation/7');
it return a generic object that implements the ResponseInterface interface? Php is automatically building something like a generic object implementing this interface or what?
2) Passing the mouse on the json_decode() function, this line:
$dettaglioHotel = json_decode($response->getBody());
the IDE say a message as "Multiple implementation" and show that there are these 2 implementations:
FIRST IMPLEMENTATION: json_decode .../vendor/guzzlehttp/guzzle/src/functions.php json_decode
SECOND IMPLEMENTATION: C:/Program Files (x86)/JetBrains/PhpStorm 2016.3.2/plugins/php/lib/php.jar!/stubs/standard/json.php
It have to use the first one (related to Guzzle) but I am not sure that is using the right one.
3) Finnally I am trying to convert into a String and print in the log this object containing the response decodification, in this way:
$dettaglioHotel = json_decode($response->getBody());
and then:
\Log::info('response: '.(string)$dettaglioHotel);
But doing in this way when try to convert into strung (by (string)$dettaglioHotel) the application crash and I obtain this error message:
in LoginBetriviusController.php line 56
at HandleExceptions->handleError('4096', 'Object of class stdClass could not be converted to string', 'C:\Users\Andrea\Documents\Betrivius\WorkSpace\betriviusExtranet\app\Http\Controllers\LoginBetriviusController.php', '56', array('userName' => 'aaa', 'pswd' => 'ddd', 'client' => object(Client), 'response' => object(Response), 'dettaglioHotel' => object(stdClass))) in LoginBetriviusController.php line 56
at LoginBetriviusController->doLogin()
at call_user_func_array(array(object(LoginBetriviusController), 'doLogin'), array()) in Controller.php line 55
at Controller->callAction('doLogin', array()) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(LoginBetriviusController), 'doLogin') in Route.php line 190
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 653
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 655
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 629
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 54
at require_once('C:\Users\Andrea\Documents\Betrivius\WorkSpace\betriviusExtranet\public\index.php') in server.php line 21
What it exactly means? Why I can't convert it into a string? How can I see the content of this object?