Skip to content

Replies: avoid bool-increment deprecation in bbp_get_reply_position_raw()#41

Closed
dd32 wants to merge 1 commit into
bbpress:trunkfrom
dd32:fix/reply-position-bool-increment
Closed

Replies: avoid bool-increment deprecation in bbp_get_reply_position_raw()#41
dd32 wants to merge 1 commit into
bbpress:trunkfrom
dd32:fix/reply-position-bool-increment

Conversation

@dd32

@dd32 dd32 commented May 20, 2026

Copy link
Copy Markdown

Fixes the PHP 8.3+ Increment on type bool has no effect warning emitted from bbp_get_reply_position_raw():

PHP Warning:  Increment on type bool has no effect, this will change in
the next major version of PHP in
.../bbpress/includes/replies/functions.php on line 2475

Root cause

array_search() returns false when the reply isn't in the children list returned by bbp_get_all_child_ids(). That list is built by a SQL query that excludes draft and future statuses (src/includes/common/functions.php), and is also subject to the bbp_get_all_child_ids filter. So false is returned in several realistic scenarios:

  • The reply has post_status of draft or future.
  • The reply's post_parent doesn't match the $topic_id passed in (callers pass a stale $topic_id, or the reply was moved).
  • A plugin filters the reply out via the bbp_get_all_child_ids filter (moderation plugins hiding pending replies, etc.).
  • Object-cache staleness for the bbpress_posts cache group.
  • $reply_id resolves to 0 or to a reply outside this topic.

In all of those, ++$reply_position then operates on false, 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_position check, and explicitly reset to 0 in 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.

…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

JJJ commented May 20, 2026

Copy link
Copy Markdown
Contributor

Fixed in trunk via https://bbpress.trac.wordpress.org/changeset/7409

@JJJ JJJ closed this May 20, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants