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


Groups > comp.lang.php > #6637 > unrolled thread

Errors Related to Same Path Through Real and Symbolic Link References

Started bySMH <garyconditswellhungrelative@yahooDOT.com>
First post2012-07-22 03:53 +0000
Last post2012-07-22 09:05 -0600
Articles 3 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  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

#6637 — Errors Related to Same Path Through Real and Symbolic Link References

FromSMH <garyconditswellhungrelative@yahooDOT.com>
Date2012-07-22 03:53 +0000
SubjectErrors Related to Same Path Through Real and Symbolic Link References
Message-ID<XnsA09846199434BSMH1960@88.198.244.100>
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.

Here is more detail:

The included file is named "globalsLib.php."  In it are defined constants 
and common functions.  Important in this post is that there is a function 
__autoload() defined on line 39.

This file "globalsLib.php" is located in the directory 
"Z:\service.web.Root\PHPClasses"  (yes, the system is Windows [7])

I also have a directory "Z:\Development".  It contains a subdirectory 
"PHPClasses" which is symbolically linked to "Z:\service.web.Root
\PHPClasses". and so the "Z:\Development\PHPClasses" points to that as the 
real directory.

Inside "Z:\Development" is a script "index.php" which contains as follows:

line 5:  require_once('globalsLib.php');
line 19: include 'SySInfo.php';

Inside the "SysInfo.php" file on line 11 is require_once('globalsLib.php');

Here is the PHP output when requesting "http://localhost/development/" 
(which reads the script "Z:\Development\index.php"

   Notice: Constant PATH_SEPARATOR already 
   defined in Z:\service.web.Root\PHPClasses\globalsLib.php 
   on line 26

   Fatal error: Cannot redeclare __autoload() (previously 
   declared in Z:\service.web.Root\PHPClasses\globalsLib.php:39) 
   in Z:\Development\PHPClasses\globalsLib.php on line 41

All of this is clearly caused by PHP correctly not knowing what that a 
symbolic link is pointing to the same directory.

I am almost certainly violating at least ONE, and probably a DOZEN Best 
Practice rules in using PHP.  Either you know the name of a book or two on 
PHP or general programming that I absolutely MUST read, or you have a set of 
rules you have developed yourself.

I would appreciate your advice.

[toc] | [next] | [standalone]


#6638

From"J.O. Aho" <user@example.net>
Date2012-07-22 08:30 +0200
Message-ID<a71kvpFra1U1@mid.individual.net>
In reply to#6637
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

[toc] | [prev] | [next] | [standalone]


#6639

FromMartin Leese <please@see.Web.for.e-mail.INVALID>
Date2012-07-22 09:05 -0600
Message-ID<juh4rf$2f4$1@dont-email.me>
In reply to#6637
SMH wrote:
...
> I am almost certainly violating at least ONE, and probably a DOZEN Best 
> Practice rules in using PHP.  Either you know the name of a book or two on 
> PHP or general programming that I absolutely MUST read, or you have a set of 
> rules you have developed yourself.

I use the on-line manual at:
http://php.net/manual/en/

in combination with the paper book "PHP: The
Complete Reference" by Steven Holzner.

-- 
Regards,
Martin Leese
E-mail: please@see.Web.for.e-mail.INVALID
Web: http://members.tripod.com/martin_leese/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web