Skip to content

Commit

Permalink
System notice when json_url() retrieves non-existent member
Browse files Browse the repository at this point in the history
An additional check and returning false allows caller to handle errors
gracefully.

Fixes #15791
  • Loading branch information
dregad committed Apr 27, 2013
1 parent 17e5c78 commit e1a265c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/json_api.php
Expand Up @@ -36,17 +36,19 @@
/**
* Get a chunk of JSON from a given URL.
* @param string URL
* @param string Top-level member to retrieve
* @return multi JSON class structure
* @param string Optional top-level member to retrieve
* @return multi JSON class structure, false in case of non-existent member
*/
function json_url( $p_url, $p_member = null ) {
$t_data = url_get( $p_url );
$t_json = json_decode( utf8_encode($t_data) );

if( is_null( $p_member ) ) {
return $t_json;
} else {
} else if( property_exists( $t_json, $p_member ) ) {
return $t_json->$p_member;
} else {
return false;
}
}

Expand Down

0 comments on commit e1a265c

Please sign in to comment.