Skip to content

Instantly share code, notes, and snippets.

@tim-cotten
Created March 5, 2021 19:29
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/2ed837a4e083010750bbb3fa71537221 to your computer and use it in GitHub Desktop.
Save tim-cotten/2ed837a4e083010750bbb3fa71537221 to your computer and use it in GitHub Desktop.
PHP Bugs: Property Problems (Example F)
<?php
// ... $desc should be a JSON string ...
if (!empty($desc)) {
try {
$desc_obj = json_decode($desc);
if (!is_object($desc_obj)) {
throw new Exception();
}
$action = !empty($desc_obj->action) ? $desc_obj->action : 'none';
$reasons = !empty($desc_obj->reasons) ? explode(',', $desc_obj->reasons) : array();
} catch (Exception $e) {
$action = "none";
$reasons = array();
}
// ... parsing logic for $reasons ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment