Opened 7 years ago
Closed 4 years ago
#43674 closed enhancement (duplicate)
require() vs require_once()
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Bootstrap/Load | Keywords: | has-patch 2nd-opinion |
Focuses: | Cc: |
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)
Change History (3)
Note: See
TracTickets for help on using
tickets.
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.