Home > Archive > PHP Language > May 2004 > calling functions with include
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
calling functions with include
|
|
| paradox 2004-05-13, 1:30 am |
| suppose i have...
<?php
include("common_functions.php");
fxn1();
fxn2();
?>
i want fxn1 and fxn2 to be on the common_functions.php page, but every time
i do that i get a Fatal Error: Call to undefined function: fxn1() in
/home/paradox/public_html/index.php
I'm guessing i would get an error for fxn2 but since it's a fatal error
the code never gets executed far enough to see if it happens.
does it make a difference if i put a space after the one aka fxn1 () or
fxn1() or are they same? I've seen them written differently on different
sites.
if i call fxn1() and fxn2() directly from common_functions.php it works
beautifully, it's only when i try calling it from index.php using the
include feature
i've used "include" and "require_once" but i thought by doing it would
basically cut and paste all the code from common_function.php into the
index.php so that i could just call the function with no worries.
| |
| Janwillem Borleffs 2004-05-13, 5:30 pm |
| paradox wrote:
> suppose i have...
>
> <?php
> include("common_functions.php");
> fxn1();
> fxn2();
>
Check if the common_functions.php file resides in the same directory as the
script that includes it and that this script is called/included from the
same directory.
Below is a situation which could cause an error:
Directory structure:
../index.php (file in root dir, accessed by the browser)
../files/include.php (includes common_functions.php)
../files/common_functions.php
When index.php includes the include.php file, the include call to
common_functions.php in include.php should have the same path as index.php
uses to include include.php:
index.php:
<? include "files/include.php" ?>
include.php:
<? include "files/common_functions.php" ?>
Another way to test this is to use require instead of include. The require
construct throws a fatal error, where include only throws a warning, which
is probably surpressed in your configuration.
JW
|
|
|
|
|