Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1 is less forgiving about arrays. #1493

Open
Ipstenu opened this issue Jul 20, 2023 · 3 comments
Open

PHP 8.1 is less forgiving about arrays. #1493

Ipstenu opened this issue Jul 20, 2023 · 3 comments

Comments

@Ipstenu
Copy link

Ipstenu commented Jul 20, 2023

After updating to PHP 8.1.9, I ran into an issue I didn't see on PHP 7x

I have a repeating group that includes cmb2_attached_posts ( https://github.com/CMB2/cmb2-attached-posts/ -- used with minimal hacks for my custom post types and changing verbiage).

https://github.com/LezWatch/lwtv-plugin/blob/production/cpts/characters/cmb2-metaboxes.php#L184

When I use it in a repeating group, I get errors and this is in the log:

Stack trace:
#0 /home/wp-content/plugins/cmb2/includes/CMB2_Field.php(148): CMB2_Field->_set_field_defaults('lezchars_show_i...')
#1 /home/wp-content/plugins/cmb2/includes/CMB2.php(1401): CMB2_Field->__construct(Array)
#2 /home/wp-content/plugins/lwtv-plugin/plugins/cmb2/cmb2-attached-posts/init.php(640): CMB2->get_field('lezchars_show_i...', Object(CMB2_Field))
#3 /home/wp-content/plugins/lwtv-plugin/plugins/cmb2/cmb2-attached-posts/init.php(614): WDS_CMB2_Attached_Posts_Field->maybe_callback(Object(WP_Query), Array)
#4 /home/wp-includes/class-wp-hook.php(308): WDS_CMB2_Attached_Posts_Field->modify_query(Object(WP_Query))
#5 /home/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
#6 /home/wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#7 /home/wp-includes/class-wp-query.php(1833): do_action_ref_array('pre_get_posts', Array)
#8 /home/wp-includes/class-wp-query.php(3749): WP_Query->get_posts()
#9 /home/wp-includes/post.php(2415): WP_Query->query(Array)
#10 /home/wp-admin/includes/ajax-actions.php(2225): get_posts(Array)
#11 /home/wp-includes/class-wp-hook.php(308): wp_ajax_find_posts('')
#12 /home/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
#13 /home/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#14 /home/wp-admin/admin-ajax.php(188): do_action('wp_ajax_find_po...')
#15 {main}
  thrown in /home/wp-content/plugins/cmb2/includes/CMB2_Field.php on line 1373

I edited /includes/CMB2_Field.php to kick out WHAT the value of $args was if it was a string, and it came back with the ID name (in this case 'show').

I cannot for the life of me see where that's being passed back and muddled, but I did figure out that if I edited _set_field_defaults and moved the check for parse args ABOVE the filter, it corrected it and I didn't have that error anymore.

                // Set up blank or default values for empty ones.
                $args = wp_parse_args( $args, $defaults );

This maybe is a bug for attached posts, but since the only fix I can find is in the main plugin, it seemed like a more logical place for it.

(PS: https://github.com/CMB2/cmb2-attached-posts/ is a wonderful plugin and I would love to see it maintained)

@jtsternberg
Copy link
Member

Can you provide the actual PHP error it's throwing? You provided the stack trace, but not the actual error.

@Ipstenu
Copy link
Author

Ipstenu commented Jul 20, 2023

Whoops!

[20-Jul-2023 00:34:43 UTC] PHP Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /home/wp-content/plugins/cmb2/includes/CMB2_Field.php:1371

NB: My output actually says 1375 because I had thrown some testing error_log lines in there to figure out what the heck WAS the string in question.

@Ipstenu
Copy link
Author

Ipstenu commented Jul 20, 2023

FYI putting my money where my mouth is, this is my full fork of attached posts - CMB2/cmb2-attached-posts#72 - I can't really test this without the fork, since out of the box, you can only use one instance of attached-posts and ... well. Yeah. I'm your local weirdo.

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

No branches or pull requests

2 participants