Skip to content

Commit

Permalink
Coding Standards: Explicitly return false in magic __isset() meth…
Browse files Browse the repository at this point in the history
…ods.

This commit fixes an issue where some magic `__isset()` methods were potentially returning `void` (if the prop is not in an allow-listed array of fields) instead of an explicit boolean `false`.

Addressed methods:
* `WP_Comment::__isset()`
* `WP_Query::__isset()`

Follow-up to [28523], [31151], [34583], [34599].

Props justlevine.
See #52217.

git-svn-id: https://develop.svn.wordpress.org/trunk@59337 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Nov 3, 2024
1 parent 0a45a6c commit 78602b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/wp-includes/class-wp-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,16 @@ public function populated_children( $set ) {
*
* @since 4.4.0
*
* @param string $name Property name.
* @return bool
* @param string $name Property to check if set.
* @return bool Whether the property is set.
*/
public function __isset( $name ) {
if ( in_array( $name, $this->post_fields, true ) && 0 !== (int) $this->comment_post_ID ) {
$post = get_post( $this->comment_post_ID );
return property_exists( $post, $name );
}

return false;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -4011,6 +4011,8 @@ public function __isset( $name ) {
if ( in_array( $name, $this->compat_fields, true ) ) {
return isset( $this->$name );
}

return false;
}

/**
Expand Down

0 comments on commit 78602b4

Please sign in to comment.