FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Errors Related to Same Path Through Real and Symbolic Link References
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Errors Related to Same Path Through Real and Symbolic Link References [message #178710] Sun, 22 July 2012 03:53 Go to next message
SMH is currently offline  SMH
Messages: 3
Registered: July 2012
Karma: 0
Junior Member
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.
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 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
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
Re: Errors Related to Same Path Through Real and Symbolic Link References [message #178712 is a reply to message #178710] Sun, 22 July 2012 15:05 Go to previous message
Martin Leese is currently offline  Martin Leese
Messages: 23
Registered: June 2012
Karma: 0
Junior Member
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(at)see(dot)Web(dot)for(dot)e-mail(dot)INVALID
Web: http://members.tripod.com/martin_leese/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Solution Manuals & Test Banks
Next Topic: Using PHP and JAVA applets together
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 23:50:29 GMT 2024

Total time taken to generate the page: 0.02374 seconds