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: Dave Hall
Subject: RE: [Phpgroupware-developers] Discussion: include/require stateme nts
Date: Tue, 10 May 2005 20:26:27 +1000

On Tue, 2005-05-10 at 10:22 +0200, Kai Hofmann wrote:
> > 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.

Where is the data to support the claim?

> 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.

createObject sits on top of this.  It deals with some of the issues
created by php.  Import in Java and C# (2 languages I have experience
with) are path aware.  If we want to go down this road within phpgw I
would suggest that the header.inc.php does a ini_set for include_path.
Then you can also have problems where a user wants the API class an gets
the app file with the same name of vise versa

> 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)
> 

Examples?

> 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 disagree, we should only use include_once/require_once to include the
concrete version of a abstract class.

> 
> > 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.

As I mentioned in my previous post Not true - require triggers a fatal
error http://php.net/phpdevel-errors#internal.e-error

It dies at that point

> The problem here is that the usage of include here has its problems and
> might
> result in errors.

Not if there are the proper checks, such as above.

> Thats because the return value of a include file can be set to any
> type/value
> via a return() statement.

As we should only be including class files (or the basic API bootstrap
functions) there should not be any standalone use of return.  Anything
other than return [false|''|0] would return true anyway, which would
only come from the included file.

> Please compare the following php manual hints for this:
> 
> http://de3.php.net/function.include
> Example 16-9, Example 16-10
> 

As I said above, not relevant to this discussion.

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

It is nice if you quote text, rather than make vague references.  I
found 2 references that snippet, I will quote them and make comments.

<quote src="http://php.net/include#AEN4941";>
<!-- snip code block -->
Because include() and require() are special language constructs, you
must enclose them within a statement block if it's inside a conditional
block.
</quote>

I did include it within a conditional block in the example I gave.

<quote src="http://php.net/include#AEN4952";>
Because include() is a special language construct, parentheses are not
needed around its argument. Take care when comparing return value. 
</quote>

The syntax in my example might need to be updated.  This is a minor fix,
*if* it is needed.  I don't have time to play with it tonight.

Cheers

Dave
-- 
Dave Hall (aka skwashd)
API Coordinator
phpGroupWare
-------------------------------------------------------------------------
Do you think if Bill Gates got laid in high school, do you think there'd 
be a Microsoft?  Of course not.
Underwear Goes Inside The Pants by Lazy Boy





reply via email to

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