--- In [email protected], Pete <[EMAIL PROTECTED]> wrote:
> In message <[EMAIL PROTECTED]>, Steve Harp
> <[EMAIL PROTECTED]> writes
> >Hi All,
> >
> >If I understand the manual, require_once() is used when code should
> >only  be included once.  I have a funcs.php that contains several
> >functions used by various scripts.  When I have a.php that uses
> >require_once('funcs.php'), then I start a script as follows:
> >
> ><?php
> >  require_once('funcs.php');
> >  require_once('a.php');    // barfs here
> >
> >  // do some cool stuff
> >?>
> >
> >I get an error from the Zend debugger, "Compile Error..funcs.php line
> >4 - Cannot redeclare func_name() (previously declared in funcs.php". 
> >What am I doing wrong?  The php manual says "if the code from a file
> >has already been included, it will not be included again". 
> >Apparently, the require_once() function is not working or I'm not
> >understanding its' usage.
> 
> You seem to be misunderstanding the 'it will not be included again' bit.
> It actually means the file funcs.php will not be included again.
> Suppose you have a loop, and 'require funcs.php' is within that loop,
> then it will be included x times.  If you use require_once within that
> loop, then funcs.php will be included just once.
> 
> As you are using it at the top of the file, which is only 'passed' once,
> it makes no difference whether you 'require' or 'require_once'.
> 
> If you have a function do_it() in both funcs.php, and a.php, then which
> one should the compiler use?  If you just drop the re-usable functions
> in anywhere, then you are heading for problems.  A more elegant plan
> should be made.  Using your method, you can spend all day recoding
> do_it(), only to find out that it was the wrong function.

I don't think you understood the scenario.  a.php does not contain a
function called func_name().  It contains a require_once('funcs.php')
and funcs.php contains func_name().  funcs.php is the only file in the
project that contains func_name() but func_name() is used in several
files; hense, the inclusion.  When I start a php file with a
require_once() for both a.php and funcs.php, I get the error.  I would
expect php to see that the funcs.php file was already loaded from
within a.php and not try to load it a second time.

Steve





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/HKFolB/TM
--------------------------------------------------------------------~-> 

Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




Reply via email to