Re: [PHP] Function Declared in Included File Not Being Found
- From: robert@xxxxxxxxxxxxx (Robert Cummings)
- Date: Fri, 11 May 2007 19:53:20 -0400
Files are included/required at run-time. As such, the function has not
been declared when you make reference to it since the require occurs
later. Move the require to the top. As a test, feel free to explicitly
define the function at the bottom without using a require.
Cheers,
Rob.
On Fri, 2007-05-11 at 16:43 -0400, Chris wrote:
Hello,--
According to the PHP manual on functions (http://www.php.net/manual/
en/language.functions.php):
"In PHP 3, functions must be defined before they are referenced. No
such requirement exists since PHP 4. Except when a function is
conditionally defined..."
If that is true then why does the following not work as I expect?
I expect the result to be "Function was called!" but it actually is
"Function test() does not exist!".
File: a.php
<?php
if (function_exists('test')) {
echo test();
}
else {
echo "Function test() does not exist!";
}
require 'b.php';
?>
-------------------------------
File: b.php
<?php
require 'c.php';
?>
-------------------------------
File: c.php
<?php
function test() {
return "Function was called!";
}
?>
Chris
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
.
- Follow-Ups:
- References:
- Prev by Date: Re: [PHP] Function Declared in Included File Not Being Found
- Next by Date: Re: [PHP] Help with CURL please
- Previous by thread: Re: [PHP] Function Declared in Included File Not Being Found
- Next by thread: Re: [PHP] Function Declared in Included File Not Being Found
- Index(es):