Replies: avoid bool-increment deprecation in bbp_get_reply_position_raw()#41
Closed
dd32 wants to merge 1 commit into
Closed
Replies: avoid bool-increment deprecation in bbp_get_reply_position_raw()#41dd32 wants to merge 1 commit into
dd32 wants to merge 1 commit into
Conversation
…aw(). When array_search() cannot find the reply in the children list returned by bbp_get_all_child_ids() — possible for draft/future replies, replies filtered out via the 'bbp_get_all_child_ids' filter, or in cache-stale conditions — it returns false, and the subsequent ++$reply_position operates on a bool. PHP 8.3+ deprecates increment on bool, and PHP 9 will make it a fatal. Cast result to 0 in the not-found case to preserve the existing return value while removing the deprecation. See https://bbpress.trac.wordpress.org/ticket/3671
JJJ
approved these changes
May 20, 2026
Contributor
|
Fixed in trunk via https://bbpress.trac.wordpress.org/changeset/7409 |
dd32
pushed a commit
that referenced
this pull request
May 20, 2026
…raw()` Fixes the PHP 8.3+ `Increment on type bool has no effect` warning, guarding the increment behind a `false !== $reply_position` check, and explicitly resetting to `0` if not-found. In trunk, for 2.7. Props dd32. Fixes: #3672. From: #41 git-svn-id: https://bbpress.svn.wordpress.org/trunk@7409 9866e705-20ec-0310-96e7-cbb4277adcfb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the PHP 8.3+
Increment on type bool has no effectwarning emitted frombbp_get_reply_position_raw():Root cause
array_search()returnsfalsewhen the reply isn't in the children list returned bybbp_get_all_child_ids(). That list is built by a SQL query that excludesdraftandfuturestatuses (src/includes/common/functions.php), and is also subject to thebbp_get_all_child_idsfilter. Sofalseis returned in several realistic scenarios:post_statusofdraftorfuture.post_parentdoesn't match the$topic_idpassed in (callers pass a stale$topic_id, or the reply was moved).bbp_get_all_child_idsfilter (moderation plugins hiding pending replies, etc.).bbpress_postscache group.$reply_idresolves to0or to a reply outside this topic.In all of those,
++$reply_positionthen operates onfalse, which is a deprecated no-op in PHP 8.3+ and a fatal in PHP 9. The function subsequently returns(int) false === 0— silently claiming the reply is in lead-post position. The deprecation is exposing a latent silent-wrong-answer bug.Fix
Guard the increment behind a
false !== $reply_positioncheck, and explicitly reset to0in the not-found case. This preserves the current return-0 behaviour for any downstream consumer while removing the deprecation.Related
Test environment
PHP 8.4.21, bbPress 2.7.0-alpha-2 / current trunk.