Coding Standards: Explicitly return false in magic __isset() methods.

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.
Built from https://develop.svn.wordpress.org/trunk@59337


git-svn-id: http://core.svn.wordpress.org/trunk@58723 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2024-11-03 23:03:19 +00:00
parent 5ef0c89c61
commit 2dfcb9ea56
3 changed files with 7 additions and 3 deletions

View File

@ -351,14 +351,16 @@ final class WP_Comment {
* *
* @since 4.4.0 * @since 4.4.0
* *
* @param string $name Property name. * @param string $name Property to check if set.
* @return bool * @return bool Whether the property is set.
*/ */
public function __isset( $name ) { public function __isset( $name ) {
if ( in_array( $name, $this->post_fields, true ) && 0 !== (int) $this->comment_post_ID ) { if ( in_array( $name, $this->post_fields, true ) && 0 !== (int) $this->comment_post_ID ) {
$post = get_post( $this->comment_post_ID ); $post = get_post( $this->comment_post_ID );
return property_exists( $post, $name ); return property_exists( $post, $name );
} }
return false;
} }
/** /**

View File

@ -4011,6 +4011,8 @@ class WP_Query {
if ( in_array( $name, $this->compat_fields, true ) ) { if ( in_array( $name, $this->compat_fields, true ) ) {
return isset( $this->$name ); return isset( $this->$name );
} }
return false;
} }
/** /**

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.8-alpha-59336'; $wp_version = '6.8-alpha-59337';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.