phpgroupware-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Phpgroupware-developers] Discussion: include/require stateme nts


From: Kai Hofmann
Subject: RE: [Phpgroupware-developers] Discussion: include/require stateme nts
Date: Tue, 10 May 2005 10:22:34 +0200

> The use of includes/requires
> should be quite limited as people should be using
> createObject/ExecMethod

When making API calls this is surely the best way. But at the same time
createObject/ExecMethod create the biggest overhead we have as I know from
performance analyses.
So I would like to propose to use require_once() within an application
as well as within the api itself for the following reasons:

1. All other programming languages use a mechanism like this for their
   source dependencies:
   * C/C++: #inlcude
   * java: import
   * etc.
2. You can easily see the dependencies of a source file very quickly, when
the
   require statements are placed near the head of the file.
3. Each source file itself knows which dependencies it has, so only required
   files will be loaded at runtime.
   (This is important, because at the moment we load often a lot of things
that
   are not required - which costs performance)

By using require within the api and an application, I mean that it should be
only
used for things that are included from within the same module scope.

So calls from a module to the api or to another module should still use
createObject/ExecMethod.

> I think there are some occassions (setup and header.inc.php) 
> where using
> something like the example below is more appropriate than just dumping
> the user with an error.
> 
> if ( !include_once('file.php') )
> {
>       die('Your install is fux0r contact your sysadmin');
> }

Thats nearly the same as when using require, except that you have an extra
error message.
The problem here is that the usage of include here has its problems and
might
result in errors.
Thats because the return value of a include file can be set to any
type/value
via a return() statement.
Please compare the following php manual hints for this:

http://de3.php.net/function.include
Example 16-9, Example 16-10

http://docs.php.net/en/language.control-structures.html
Near the bottom: search for " Because include()" and read the following two
statements.

Greetings
   PowerStat




reply via email to

[Prev in Thread] Current Thread [Next in Thread]