Skip to:

Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#3031 closed defect (bug) (fixed)

Fatal error: Uncaught Error: [] operator not supported for strings

Reported by: hellofromtonya's profile hellofromTonya Owned by: johnjamesjacoby's profile johnjamesjacoby
Milestone: 2.6 Priority: normal
Severity: normal Version: 2.5.11
Component: General Keywords: needs-patch
Cc: chrismarslender@…


There are several spots in the codebase where an element is being added to a variable that has not yet been initialized as an array. Upon upgrading to PHP 7.1, our site popped fatal error for includes/forums/functions.php line 1800.

When a variable is not initialized to an array first, you get the following PHP Error:

Fatal error: Uncaught Error: [] operator not supported for strings...

I manually fixed it by adding the following initializers:

In includes/forums/functions.php

Line 1800 (L1969 in 2.6-alpha):

$post_stati = array();
$post_stati[] = bbp_get_public_status_id();

In includes/common/functions.php

Line 505

$topics = $topic_titles = array();

Line 537

$replies = $reply_titles = array();

In includes/forums/template.php

Line 683 (L740 in 2.6-alpha)

$post_stati = array();

In includes/users/template.php

Line 1648 (L1709 in 2.6-alpha)

$author_links = array();

Change History (15)

#1 @netweb
7 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 2.6

Thanks for the detailed ticket @hellofromTonya

I added PHP 7.1 Travis CI testing in r6132 earlier and will take a look at getting these instances fixed ASAP

Related: #2987

#2 @johnjamesjacoby
7 years ago

  • Owner set to johnjamesjacoby
  • Resolution set to fixed
  • Status changed from new to closed

In 6135:

Tools: Fix undeclared variables and incorrect variable types, for improved PHP 7.1 compatibility.

This will quiet down most of our continuous integration noise.

Props hellofromTonya. Fixes #3031.

#3 @netweb
7 years ago

#3088 & #3094 were marked as a duplicates

This ticket was mentioned in Slack in #bbpress by sergey. View the logs.

7 years ago

This ticket was mentioned in Slack in #bbpress by zakalwe. View the logs.

7 years ago

#6 @johnjamesjacoby
7 years ago

In 6647:

Fix undeclared arrays for PHP 7.1 compatibility.

Props hellofromTonya. See #3031. (2.5 branch)

#7 @johnjamesjacoby
7 years ago

In 6648:

Fix undeclared array in forum template functions for PHP 7.1 compatibility.

Props hellofromTonya. See #3031. (2.5 branch)

#8 @brody182
7 years ago

This has not been fixed, still get the error on new install with 0 forums (php 7.1.7)

Fatal error: Uncaught Error: [] operator not supported for strings in C:\xampp\htdocs\themerevel\wp-content\plugins\bbpress\includes\forums\functions.php:1800 Stack trace: #0 C:\xampp\htdocs\themerevel\wp-includes\class-wp-hook.php(298): bbp_pre_get_posts_normalize_forum_visibility(Object(WP_Query)) #1 C:\xampp\htdocs\themerevel\wp-includes\class-wp-hook.php(323): WP_Hook->apply_filters('', Array) #2 C:\xampp\htdocs\themerevel\wp-includes\plugin.php(515): WP_Hook->do_action(Array) #3 C:\xampp\htdocs\themerevel\wp-includes\class-wp-query.php(1683): do_action_ref_array('pre_get_posts', Array) #4 C:\xampp\htdocs\themerevel\wp-includes\class-wp-query.php(3248): WP_Query->get_posts() #5 C:\xampp\htdocs\themerevel\wp-includes\class-wp.php(617): WP_Query->query(Array) #6 C:\xampp\htdocs\themerevel\wp-includes\class-wp.php(735): WP->query_posts() #7 C:\xampp\htdocs\themerevel\wp-includes\functions.php(955): WP->main(Array) #8 C:\xampp\htdocs\themerevel\wp-admin\includes\post.php(1072): wp(Array) #9 C:\xampp\htdocs\themerevel\wp-a in C:\xampp\htdocs\themerevel\wp-content\plugins\bbpress\includes\forums\functions.php on line 1800
Last edited 7 years ago by brody182 (previous) (diff)

#9 @cmmarslender
7 years ago

  • Cc chrismarslender@… added
  • Resolution fixed deleted
  • Status changed from closed to reopened

I get the same error as @brody182 on a fresh install.

#10 @johnjamesjacoby
7 years ago

In 6673:

Common: cast return value to array in bbp_pre_get_posts_normalize_forum_visibility().

Trunk, for 2.6. See #3031.

#11 @it4life
7 years ago

Hi @johnjamesjacoby,
Do you plan to release this fix for 2.5.x version?

#12 @johnjamesjacoby
7 years ago

Hello @it4life, yes, I do. It will be in 2.5.14.

#13 @johnjamesjacoby
7 years ago

In 6684:

General: more PHP7.1 array fixes.

See #3031. 2.5 branch, for 2.5.14.

#14 @johnjamesjacoby
7 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

Both 2.5 and 2.6/trunk are fixed up and good to go.

#15 @netweb
6 years ago

#3204 was marked as a duplicate

Note: See TracTickets for help on using tickets.