#20298 closed enhancement (wontfix)
Change requires to require_once
Reported by: | pp3345 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.3.1 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
Wordpress partially uses "require" to include files. I'd prefer to have require_once everywhere where a file really shouldn't be included twice. I'm currently developing an HTTP-Server (https://github.com/pp3345/Pancake) with a function to keep "static" codefiles (for example files that only do class-definitions and don't actually really execute any code) in some kind of a cache so that they don't need to be loaded again on every single request in order to improve performance. When I now, for example, load the wp-includes/class-wp-walker.php into the cache at the beginning and then Wordpress tries to require the file again, it fails with an Fatal Error due to trying to define the class again. Using require_once instead of require in Wordpress can be done quickly and would easily fix this. Also, it could improve the codes quality a bit.
Change History (7)
#2
@
13 years ago
That would introduce some delay on each require()
and still leaves plugins out. Perhaps a better approach would be to intercept require()
and include()
calls coming from PHP.
#3
@
13 years ago
A quick look in Zend/PHPs source shows that running a require_once() instead of a require() doesn't really run a lot more code, only a few more lines. I don't think it would make a remarkable (probably not even a measurable) difference in performance, but the code would still be cleaner and you could be sure that a file doesn't get included twice by mistake.
#4
@
13 years ago
Well, one, require_once() is indeed a performance difference. It's not much, but those few lines end up checking include_path and does a hash table lookup. The include graph for WordPress is something like 100 files so it will definitely be worse for performance, even if barely measurable.
Additionally, if we change this, we then have to agree to maintain the use of require_once always. That kind of commitment (when it doesn't benefit us) is difficult to agree to or maintain.
More importantly, though, I disagree that require_once is an increase in code quality. It can hide problems, silly code, and errors; and indicates to me a decrease in quality, if anything.
Why take a performance hit when none is needed. If the include files get moved around, a require_once won't fix that anyway. Always using require_once calls is just a bad habit as far as I am concerned. There may be a few common files that are prone to multiple inclusion in a complex application, but most shouldn't be included multiple times and if you are including them multiple times you'd probably want to know about it and not just ignore it the way the _once functions do.
That's directly from Rasmus Lerdorf. Reference: http://toys.lerdorf.com/archives/34-Flickr-API-Fun.html#c3019.
#6
@
11 years ago
- Keywords close removed
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
See @nacin's comment:4:
The include graph for WordPress is something like 100 files so [require_once] will definitely be worse for performance, even if barely measurable.
Additionally, if we change this, we then have to agree to maintain the use of require_once always. That kind of commitment (when it doesn't benefit us) is difficult to agree to or maintain.
More importantly, though, I disagree that require_once is an increase in code quality. It can hide problems, silly code, and errors; and indicates to me a decrease in quality, if anything.
Related: #19921