Skip to content

Commit e1a265c

Browse files
committedApr 27, 2013
System notice when json_url() retrieves non-existent member
An additional check and returning false allows caller to handle errors gracefully. Fixes #15791
1 parent 17e5c78 commit e1a265c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
 

‎core/json_api.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@
3636
/**
3737
* Get a chunk of JSON from a given URL.
3838
* @param string URL
39-
* @param string Top-level member to retrieve
40-
* @return multi JSON class structure
39+
* @param string Optional top-level member to retrieve
40+
* @return multi JSON class structure, false in case of non-existent member
4141
*/
4242
function json_url( $p_url, $p_member = null ) {
4343
$t_data = url_get( $p_url );
4444
$t_json = json_decode( utf8_encode($t_data) );
4545

4646
if( is_null( $p_member ) ) {
4747
return $t_json;
48-
} else {
48+
} else if( property_exists( $t_json, $p_member ) ) {
4949
return $t_json->$p_member;
50+
} else {
51+
return false;
5052
}
5153
}
5254

0 commit comments

Comments
 (0)
Please sign in to comment.