Last active
March 5, 2021 02:22
-
-
Save tim-cotten/f0a226f2e23ff1224fc4a8592a8008b8 to your computer and use it in GitHub Desktop.
PHP Bugs: Confusing Non-Objects for Objects (Example G)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function exchange_send_message_raw($context, $content) | |
{ | |
$location = "https://test.cotten.io/exchange/raw_message.php"; | |
$request = array('direction' => 1, // outgoing | |
'context' => $context, | |
'content' => json_encode($content)); | |
$message = null; | |
try { | |
$response = ProxyPostClient::request($location, $request); | |
$response_obj = json_decode($response); | |
if (empty($response_obj)) { | |
throw new Exception('Empty response.'); | |
} | |
if (!isset($response_obj->content)) { | |
throw new Exception('Missing property: content in response'); | |
} | |
$message = $response_obj->content; | |
print_formatted_log("Exchange Response: Success"); | |
print_formatted_log(json_encode($response_obj)); | |
echo "\n"; | |
} catch (Exception $e) { | |
print_formatted_log("Exchange Response: Error: " . $e->getMessage()); | |
print_formatted_log($response); // raw text response | |
echo "\n"; | |
} | |
return $message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment