TukuToi/tukutoi-shortcodes

Missing $tag parameter

Opened this issue · 2 comments

I have attached screenshots of my implementation and the error.
Screenshot 2022-06-28 at 10 53 12

Screenshot 2022-06-28 at 10 52 51

That is probably only happening on PHP8, which CP does not support as of yet.
(see https://php.watch/versions/8.0/deprecate-required-param-after-optional)

I probably have to pass null instead of $content = '' when I use the third argument (which I always do) but do not pass a value for $content.

function shortcode_callback( array $atts, string $content, string $shortcode_tag ) {
    $atts = shortcode_atts( array(
        'foo' => 'no foo',
        'bar' => 'default bar'
    ), $atts, 'bartag' );
}
add_shortcode( 'bartag', 'shortcode_callback' );

I will schedule that for this year so (if) CP gets PHP8 compliant, this plugin will too.
I never even noticed it because CP does not run (officially) on PHP8

Interesting:
https://wordpress.org/support/topic/php-deprecated-notice-when-updating-to-php-8/

  1. This is a PHP8 only error
  2. According above ticket there are some whatever bugs even in PHP that attempt to "fix" this. This discussion alone makes me doubt PHP devs themselves know what they want to do with this php/php-src#8024

However, to avoid errors, I guess I can just omit $content = null and pass $content instead.
Since the shortcode won't be used as an enclosing one, nothing is passed to it, neither it is used in the code.
The only problem is, the Codex itself suggests to use $content = null:
https://codex.wordpress.org/Shortcode_API > Handling Attributes > A suggested code idiom for declaring defaults and parsing attributes in a shortcode handler is as follows:[..]
https://codex.wordpress.org/Shortcode_API > Enclosing vs self-closing shortcodes > If a shortcode macro is used to enclose content, its handler function will receive a second parameter containing that content. Users might write shortcodes in either form, so it is necessary to allow for either case by providing a default value for the second parameter to your handler function: [...]

But I tested with removing the = null and found no issues so far. I guess, it is just a bad documentation consequence because I see the error pops up in hundreds of threads in the WP Forum since PHP8

I will test it a bit on my sites with the null removed, and if all good, push the change.