Re: include file
- From: sheldonlg <sheldonlg>
- Date: Sun, 30 Nov 2008 07:38:24 -0500
student4lifer@xxxxxxxxx wrote:
Hello,
I have a.php that includes functions.php and b.php that also uses
some function in functions.php as follows.
<? php
include("functions.php");
include ("b.php");
?>
For some reason, I got error message "somefunction() not found"
originated from b.php when I ran a.php. When I tried to ALSO include
functions.php in b.php, I got error message
Fatal error: Cannot redeclare somefunction() (previously declared in
functions.php. What am I missing? Thanks.
My guess is that you had someFunction() in functions.php and called somefunction.php in b.php and that is why it didn't find it. When you included functions.php in b.php, and still left functions.php in a.php, the function someFunction() became doubly defined -- which is not allowed. (The error message is always entirely in lower case, so it might really have meant someFunction() ).
1 - Check that what you are calling in b.php is, indeed, what the function is in functions.php. Remember that case sensitivity counts.
2 - Change include (or require) to include_once (or require_once). Use include for things that you specifically want included in multiple places and are NOT functions. For example, you may have a dropdown list and you want that to be included in several place, you might build the <option value="...">something</option> with print statements and save it in a separate file. You would then include it in the several places that in building the form. NEVER omit t5he _once when the included file contains functions. Think of the added _once as similar to the C preprocessor function #ifndef.
.
- References:
- include file
- From: student4lifer
- include file
- Prev by Date: Re: header()
- Next by Date: percentage based output
- Previous by thread: Re: include file
- Next by thread: percentage based output
- Index(es):