Re: Errors Related to Same Path Through Real and Symbolic Link References [message #178711 is a reply to message #178710] |
Sun, 22 July 2012 06:30 |
J.O. Aho
Messages: 194 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 22/07/12 05:53, SMH wrote:
> I am using "require_once" to include a PHP file that defines constants and
> commonly used functions. It is in a main script and also in support scripts
> that are themselves included in the main script. The main script is in a
> "development" directory, and that directory contains a symbolic link to
> included files. I am getting a FATAL ERROR (function in included file is
> re-declared) because there is a reference to an included script through a
> real path and one through a symbolically linked path.
The obvious solution is to see that you include the file just once.
Another work around is to use c/c++ like define checks:
<?php
if(!defined('__MYPHPFILENAME'))
{
// define the value, so next include won't come in here
define('__MYPHPFILENAME', true);
function first_function_of_yours() {
// your code here
}
function second_function_of_yours() {
// your code here
}
}
?>
or you could do for each function:
if(!function_exists('first_function_of_yours')) {
function first_function_of_yours() {
// your code here
}
}
and you have to see if values are defined before you define those (if
you use global values).
If you really want to do it the right way, just see to just include the
file once, no matter if it's the original file or a symlink.
--
//Aho
|
|
|