I hope someone could help me with the following error. I can't find a solution.
var_dump($curl->response);
echo '<br><br><br><br>';
$result = json_decode(json_encode($curl->response), true);
var_dump($result);
echo '<br><br><br><br>';
$key = 'email';
foreach ($result as $k => $v) {
echo $k . '->' . $result[$k] . '<br>';
if ($k == $key) {
echo $result[$key] . '<br>';
}
}
//$result[$key];
If I run I get the following data (I changed some value for security reason)
object(stdClass)#2085 (6) {
["account_type"]=> string(0) ""
["email"]=> string(17) "sales@example.com"
["firstName"]=> string(4) "Mary"
["lastName"]=> string(6) "McLonn"
["organizer_key"]=> string(19) "1234567890123456789"
["version"]=> string(1) "3" }
array(6) {
["account_type"]=> string(0) ""
["email"]=> string(17) "sales@example.com"
["firstName"]=> string(4) "Mary"
["lastName"]=> string(6) "McLonn"
["organizer_key"]=> string(19) "1234567890123456789"
["version"]=> string(1) "3" }
account_type->
email->sales@example.com
sales@example.com
firstName->Mary
lastName->McCann
organizer_key->1234567890123456789
version->3
Everything ok here. But if uncomment the last line $result[$key], it gives me the followinf error:
Slim Application Error
The application could not run because of the following error:
Details
Type: ErrorException
Code: 8
Message: Undefined index: email
File: \App\Controllers\Api\V1\binar\Model.php
Line: 313
Trace
#0 \App\Controllers\Api\V1\binar\Model.php(313): Slim\Slim::handleErrors(8, 'Undefined index...', 'App\Controllers\Api...', 313, Array)
#1 \App\Controllers\Api\V1\binar\Model.php(352): App\Controllers\Api\V1\binar\Model::send('https://api.get...', 'POST', Array, Array, false)
#2 \App\Controllers\Api\V1\binar\binar.php(47): App\Controllers\Api\V1\binar\Model->applyCredentials()
#3 [internal function]: App\Controllers\Api\V1\binar\binar::demo()
#4 \vendor\slim\slim\Slim\Route.php(173): call_user_func_array(Array, Array)
#5 [internal function]: Slim\Route->Slim\{closure}()
#6 \vendor\slim\slim\Slim\Route.php(468): call_user_func_array(Object(Closure), Array)
#7 \vendor\slim\slim\Slim\Slim.php(1355): Slim\Route->dispatch()
#8 \vendor\slim\slim\Slim\Middleware\Flash.php(85): Slim\Slim->call()
#9 \vendor\slim\slim\Slim\Middleware\MethodOverride.php(92): Slim\Middleware\Flash->call()
#10 \App\Resources\Middleware\APMiddleware.php(28): Slim\Middleware\MethodOverride->call()
#11 \App\Resources\Middleware\LPMiddleware.php(31): App\Resources\Middleware\APMiddleware->call()
#12 \vendor\slim\slim\Slim\Middleware\PrettyExceptions.php(67): App\Resources\Middleware\LPMiddleware->call()
#13 \vendor\slim\slim\Slim\Slim.php(1300): Slim\Middleware\PrettyExceptions->call()
#14 \index.php(8): Slim\Slim->run()
#15 {main}
The same line is working good inside the foreach, that why it shows me the email two times.
I'm using php-curl-class/php-curl-class 4.8
I really do not understand what I'm doing wrong, or where look for the solution.
Thanks for your help.
EDIT
If I do
$this->email = $curl->response->email
I get the error: Undefined property: stdClass::$email
But if I do
$this->email = (property_exists($curl->response, 'email')) ? $curl->response->email : null;
I have no error and $this->email has the correct value loaded