Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #6638

Re: Errors Related to Same Path Through Real and Symbolic Link References

From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: Errors Related to Same Path Through Real and Symbolic Link References
Date 2012-07-22 08:30 +0200
Message-ID <a71kvpFra1U1@mid.individual.net> (permalink)
References <XnsA09846199434BSMH1960@88.198.244.100>

Show all headers | View raw


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

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Errors Related to Same Path Through Real and Symbolic Link References SMH <garyconditswellhungrelative@yahooDOT.com> - 2012-07-22 03:53 +0000
  Re: Errors Related to Same Path Through Real and Symbolic Link References "J.O. Aho" <user@example.net> - 2012-07-22 08:30 +0200
  Re: Errors Related to Same Path Through Real and Symbolic Link References Martin Leese <please@see.Web.for.e-mail.INVALID> - 2012-07-22 09:05 -0600

csiph-web