[wp-trac] [WordPress Trac] #43674: require() vs require_once()

WordPress Trac noreply at wordpress.org
Mon Apr 2 13:25:31 UTC 2018


#43674: require() vs require_once()
-------------------------+-----------------------------
 Reporter:  luftaffen    |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  trunk
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 When I tried to install wordpress (in openshift, but this should not
 matter), I got the following message

 {{{
 Fatal error: Cannot redeclare maybe_hash_hex_color() (previously declared
 in /opt/app-root/src/wp-includes/formatting.php:5759) in /opt/app-root/src
 /wp-includes/formatting.php on line 5759
 }}}

 I did noticed that formatting.php is being included only twice in the code
 (using fgrep here):

 {{{
 ./wp-settings.php:require( ABSPATH . WPINC . '/formatting.php' );
 ./wp-includes/load.php:         require( ABSPATH . WPINC .
 '/formatting.php' );
 }}}

 I solved that by replacing require() with require_once(). And that leads
 to:
 is there a reason not to use require_once() to begin with?

 I can submit a patch, but in the end of the day all I did was

 {{{
 for i in $(find . -type f ); do sed -i -e 's/require( /require_once( /'
 $i; done
 }}}

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


More information about the wp-trac mailing list