[wp-trac] [WordPress Trac] #39277: get_post_galleries() produces PHP Warning in PHP 7.1 when parsing empty shortcode

WordPress Trac noreply at wordpress.org
Wed Dec 14 13:05:43 UTC 2016


#39277: get_post_galleries() produces PHP Warning in PHP 7.1 when parsing empty
shortcode
--------------------------+-----------------------------
 Reporter:  DJPaul        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Shortcodes    |    Version:  4.7
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 With WordPress 4.7 and PHP 7.1, `get_post_galleries()` produces a PHP
 Warning when given an empty gallery shortcode:

 > Illegal string offset 'src'
 > /vagrant/wp/wp-includes/media.php:3696

 This broke a probably-useless unit test in BuddyPress, but it will at
 least cause a PHP Warning if a certain common code path is triggered in
 production (and probably cause a regression in functionality).

 Here's an example PHPUnit test you can copy/paste in to quickly see the
 issue. Compare it on PHP 7.1 against PHP < 7.1.

 {{{
 public function test_this_breaks_on_php71() {
         $post_id = $this->factory->post->create( array(
                 'post_content' => 'blah [gallery] blah',
         ) );
         $gallery = get_post_galleries( $post_id, false );
         $this->assertSame( array( array( 'src' => array() ) ), $gallery );
 }
 }}}

 I think returning an empty array, rather than an pair of nested arrays
 with only one `src` key set, is actually better/more expected behaviour.

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


More information about the wp-trac mailing list