[wp-trac] [WordPress Trac] #59206: PHP Fatal error: Uncaught TypeError: Cannot access offset of type string on string in Stack trace:\n#0 [internal function]: img_caption_shortcode()

WordPress Trac noreply at wordpress.org
Fri Aug 25 17:04:47 UTC 2023


#59206: PHP Fatal error: Uncaught TypeError: Cannot access offset of type string on
string in Stack trace:\n#0 [internal function]: img_caption_shortcode()
-------------------------------+-----------------------------
 Reporter:  maltfield          |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  General            |    Version:  6.3
 Severity:  normal             |   Keywords:
  Focuses:  php-compatibility  |
-------------------------------+-----------------------------
 There appears to be a bug in WordPress 6.3 that causes a PHP Fatal Error
 when processing a "[caption]" shortcode that does not have an "id" option
 defined.

 Example error

 {{{
 ==> tech.michaelaltfield.net/error.log <==
 [Wed Aug 23 00:00:09.968658 2023] [php:error] [pid 459909] [client
 0.0.0.0:0] PHP Fatal error:  Uncaught TypeError: Cannot access offset of
 type string on string in /var/www/html/wordpress/htdocs/wp-
 includes/media.php:2147\nStack trace:\n#0 [internal function]:
 img_caption_shortcode()\n#1 /var/www/html/wordpress/htdocs/wp-
 includes/shortcodes.php(356): call_user_func()\n#2 [internal function]:
 do_shortcode_tag()\n#3 /var/www/html/wordpress/htdocs/wp-
 includes/shortcodes.php(228): preg_replace_callback()\n#4 [internal
 function]: do_shortcode()\n#5 /var/www/html/wordpress/htdocs/wp-includes
 /class-wp-hook.php(307): call_user_func_array()\n#6
 /var/www/html/wordpress/htdocs/wp-includes/plugin.php(191):
 WP_Hook->apply_filters()\n#7 /var/www/html/wordpress/htdocs/wp-
 content/themes/redacted/functions.php(309): apply_filters()\n#8 [internal
 function]: bfa_wp_trim_excerpt()\n#9 /var/www/html/wordpress/htdocs/wp-
 includes/class-wp-hook.php(309): call_user_func_array()\n#10
 /var/www/html/wordpress/htdocs/wp-includes/plugin.php(191):
 WP_Hook->apply_filters()\n#11 /var/www/html/wordpress/htdocs/wp-includes
 /post-template.php(429): apply_filters()\n#12
 /var/www/html/wordpress/htdocs/wp-includes/feed.php(226):
 get_the_excerpt()\n#13 /var/www/html/wordpress/htdocs/wp-includes/feed-
 rss2.php(103): the_excerpt_rss()\n#14 /var/www/html/wordpress/htdocs/wp-
 includes/template.php(770): require_once('...')\n#15
 /var/www/html/wordpress/htdocs/wp-includes/functions.php(1662):
 load_template()\n#16 [internal function]: do_feed_rss2()\n#17
 /var/www/html/wordpress/htdocs/wp-includes/class-wp-hook.php(309):
 call_user_func_array()\n#18 /var/www/html/wordpress/htdocs/wp-includes
 /class-wp-hook.php(331): WP_Hook->apply_filters()\n#19
 /var/www/html/wordpress/htdocs/wp-includes/plugin.php(476):
 WP_Hook->do_action()\n#20 /var/www/html/wordpress/htdocs/wp-
 includes/functions.php(1624): do_action()\n#21
 /var/www/html/wordpress/htdocs/wp-includes/template-loader.php(48):
 do_feed()\n#22 /var/www/html/wordpress/htdocs/wp-blog-header.php(19):
 require_once('...')\n#23 /var/www/html/wordpress/htdocs/index.php(17):
 require('...')\n#24 {main}\n  thrown in /var/www/html/wordpress/htdocs/wp-
 includes/media.php on line 2147, referer:
 https://tech.michaelaltfield.net/feed/
 }}}

 I recently upgraded my server to use PHP 8.2. After I did, I started
 getting these fatal PHP errors in wordpress.

 I was able to isolate the issue to one post containing a simple [caption]
 shortcode. I further distilled the shortcode to the following snippet,
 which throws the fatal error if it's added to any post

 {{{
 [caption]<a href="http://example.com"><img
 src="https://example.com/example.jpg" /></a> test[/caption]
 }}}

 Through trial-and-error, I found that the fatal error does not appear if I
 add an id option to the shortcode. For example, this is fine:

 {{{
 [caption id="whyuno" ]<a href="http://example.com"><img
 src="https://example.com/example.jpg" /></a> test[/caption]
 }}}

 According to the official wordpress documentation on the caption
 shortcode, the id option is not required (ie the option is, uh, optional).

 I'm running the latest stable version of PHP (8.2) and the latest stable
 version of WordPress (6.3) on Debian 12.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59206>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list