Skip to content

Instantly share code, notes, and snippets.

@tim-cotten
Last active March 5, 2021 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tim-cotten/f0a226f2e23ff1224fc4a8592a8008b8 to your computer and use it in GitHub Desktop.
Save tim-cotten/f0a226f2e23ff1224fc4a8592a8008b8 to your computer and use it in GitHub Desktop.
PHP Bugs: Confusing Non-Objects for Objects (Example G)
<?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