Slowang
asked on
Problem with include_once()
Hi there,
i have a problem with include_once function,
at the begining of the page,
i have this line of code
a.php
-------------------------- --
<?php
include_once('AllFunctions .inc');
......
......
.....
?>
In AllFunctions.inc has these code
-------------------------- ---------- -------
<?php
include_once('FunctionA.in c');
?>
when i try to access a.php
it returns this error:
Warning: Failed opening 'FunctionA.inc' for inclusion (include_path='.:/usr/loca l/lib/php' ) in ../inc/AllFunctions.inc on line 2
i know it has got something to do with the include_path
the include_path from phpinfo():
.:/usr/local/lib/php
how do i fix the problem??
Thank you very much~
i have a problem with include_once function,
at the begining of the page,
i have this line of code
a.php
--------------------------
<?php
include_once('AllFunctions
......
......
.....
?>
In AllFunctions.inc has these code
--------------------------
<?php
include_once('FunctionA.in
?>
when i try to access a.php
it returns this error:
Warning: Failed opening 'FunctionA.inc' for inclusion (include_path='.:/usr/loca
i know it has got something to do with the include_path
the include_path from phpinfo():
.:/usr/local/lib/php
how do i fix the problem??
Thank you very much~
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
[quote]2 - include/include_once/requi re/require _once are not functions and you do not need to write them as so.
e.g.
include "include.inc";
is perfectly fine and is recommended as functions return values and include() does not.[/quote]
true, those are not functions according to the manual.
Recommended to remove the ( ) ?
I don't agree, as with () it becomes more clear to what is related to the include and what is not; I find that my code is much more easy to read that way.
If you prefer to not use the () that is perfectly fine.
the statement that include does not return a value is however false:
from the php-manual: http://www.php.net/manual/en/function.include.php
---------
Handling Returns: It is possible to execute a return() statement inside an included file in order to terminate processing in that file and return to the script which called it. Also, it's possible to return values from included files. You can take the value of the include call as you would a normal function.
---------
another value that is returned is true or false --> was the include succesfull or not?!?
in short: include's allways return a value!
e.g.
include "include.inc";
is perfectly fine and is recommended as functions return values and include() does not.[/quote]
true, those are not functions according to the manual.
Recommended to remove the ( ) ?
I don't agree, as with () it becomes more clear to what is related to the include and what is not; I find that my code is much more easy to read that way.
If you prefer to not use the () that is perfectly fine.
the statement that include does not return a value is however false:
from the php-manual: http://www.php.net/manual/en/function.include.php
---------
Handling Returns: It is possible to execute a return() statement inside an included file in order to terminate processing in that file and return to the script which called it. Also, it's possible to return values from included files. You can take the value of the include call as you would a normal function.
---------
another value that is returned is true or false --> was the include succesfull or not?!?
in short: include's allways return a value!
Aha!
Absolutely right.
I've read the include help fine, I got ...
Note: Because this is a language construct and not a function, it cannot be called using variable functions
mixed up in my head.
As I always use require_once, I rarely have to deal with include'd code.
Richard.
Absolutely right.
I've read the include help fine, I got ...
Note: Because this is a language construct and not a function, it cannot be called using variable functions
mixed up in my head.
As I always use require_once, I rarely have to deal with include'd code.
Richard.
Or add path's to the default path where else to look.
So if the file you want to include is in the same folder as the current script you can simply do this:
include_once('myscript.php
if the file is not in the same folder as the current script; but in a folder that is included in the "include_path" setting you can also do this:
include_once('myscript.php
otherwise you will have to supply a complete path to the file in the functioncall:
include_once('/folder/subf