Why is include favored over include_once?

Discuss general development subjects that are not specific to a particular version like the versioning control system we use or other infrastructure.
jakobgt
Registered User
Posts: 4
Joined: Thu Jan 05, 2012 9:58 pm

Re: Why is include favored over include_once?

Post by jakobgt »

bantu wrote:We can change unguarded includes to guarded includes in phpBB 3.0.x if absolutely necessary. In 3.1.x we have autoloading anyway, so new code will probably be autoloaded instead of manually loaded.
Nice, but isn't __autoload a problem both for performance* and interoperability** reasons?

*: some years ago I did an experiment with __autoload and it showed it had very bad performance compared to require_once. (I don't know whether that is still true today though)....

**: If you put together two projects where each contains an __autoload function, I sense a problem, because which will be used then?

User avatar
bantu
3.0 Release Manager
3.0 Release Manager
Posts: 557
Joined: Thu Sep 07, 2006 11:22 am
Location: Karlsruhe, Germany
Contact:

Re: Why is include favored over include_once?

Post by bantu »

jakobgt wrote:Nice, but isn't __autoload a problem both for performance* and interoperability** reasons?

*: some years ago I did an experiment with __autoload and it showed it had very bad performance compared to require_once. (I don't know whether that is still true today though)....

**: If you put together two projects where each contains an __autoload function, I sense a problem, because which will be used then?
We are not using __autoload, it is deprecated. We are using SPL Autoloading for classes. See viewtopic.php?f=84&t=33237 for details.

Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: Why is include favored over include_once?

Post by Oleg »

jakobgt wrote:But as this post http://stackoverflow.com/a/194959 points out is not the case anymore in PHP5 (remember also that you have the overhead of function_exists in the guarded version).
That comparison has several issues:

1. require vs require_once files are different. In the require_once version the "define('CommonHdr', 1);" part is not in the included file and therefore is not credited against require's runtime.

2. The paths being required do not have any symlinks in them, which is where the difference between require and require_once should manifest. It seems that require tries to resolve symlinks, which is interesting as there should be no need for it, but without symlinks in the path it's not a clearly demonstrated fact.

3. There is no comparison between syscalls used in require_once path vs function/class_exists and require in the case when the file is already loaded (one would expect the check+require path to not issue any syscalls in that case).

I wouldn't base much on it.
jakobgt wrote: So my guess is that you still want to support PHP4 by guarding all of the includes, but is that really still necessary? I mean, how many PHP4 installations exists "out there on the wild wild Internet"? And how many are used for PHPBB?
phpbb 3.0.x supports php 4. We are not going to drop that support therefore the number of php 4 installations still existing is irrelevant.

Post Reply