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.

-- 
Pete Clark

http://www.hotcosta.com
http://www.spanishholidaybookings.com




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