Skip to content

Commit 4dd37fb

Browse files
authored
Merge pull request #970 from epigeyre/master
fix: prevent php warning in looks_like_json function
2 parents 09b0e99 + 50f14d2 commit 4dd37fb

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

php/class-utils.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,21 @@ public static function pathinfo( $path, $flags = 15 ) {
543543
* @return bool
544544
*/
545545
public static function looks_like_json( $thing ) {
546-
return ! empty( $thing ) && is_string( $thing ) && in_array( ltrim( $thing )[0], array( '{', '[' ), true );
546+
if ( ! is_string( $thing ) ) {
547+
return false;
548+
}
549+
550+
$thing = trim( $thing );
551+
552+
if ( empty( $thing ) ) {
553+
return false;
554+
}
555+
556+
if ( ! in_array( $thing[0], array( '{', '[' ), true ) ) {
557+
return false;
558+
}
559+
560+
return true;
547561
}
548562

549563
/**

0 commit comments

Comments
 (0)