WordPress.org

Make WordPress Core

Opened 19 months ago

Last modified 19 months ago

#43674 new enhancement

require() vs require_once()

Reported by: luftaffen Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Bootstrap/Load Keywords: has-patch 2nd-opinion
Focuses: Cc:
PR Number:

Description

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

Attachments (1)

4367.diff (67.8 KB) - added by luftaffen 19 months ago.

Download all attachments as: .zip

Change History (2)

@luftaffen
19 months ago

#1 @johnbillion
19 months ago

  • Component changed from General to Bootstrap/Load
  • Keywords has-patch 2nd-opinion added
  • Version trunk deleted

Thanks for the ticket, @luftaffen . You're probably right that most files should switch to (include|require)_once, but that will need some more investigation, including its performance impact, if any.

The root cause of the problem you're seeing is already being addressed in #43609.

Note: See TracTickets for help on using tickets.