www.webdeveloper.com
Results 1 to 3 of 3

Thread: Errors Caused Real and Symbolically-Linkied Paths To Same File

  1. #1
    Join Date
    Jul 2010
    Posts
    66

    Errors Caused Real and Symbolically-Linkied Paths To Same File

    I am now mired in a confusion of include/require paths. This will be challenging perhaps for the experience PHP coder.

    The question is: What is the best way to make sure I don't get PHP Notices, Warnings, or Errors related with redefinitions of constants or redeclarations of functions/other code when I have PHP files including other PHP files which may include others. NOTE CAREFULLY: in this instance: require_once() is not working, for reasons explained below:

    Suppose I have a two REAL directories/folders which are called
    "Z:\Development"
    "Z:\service.web.Root"

    Within the directory "Z:\service.web.Root" is the real subdirectory "PHPClasses" (full path is "Z:\service.web.Root\PHPClasses")

    Within the directory "Z:\Development" is the subdirectory "PHPClasses" also, but it is a symbolic link that points to the PHPClasses directory in the Z:\service.web.Root. This is convenient, because it does not require copying (replicating) PHP or other support (Javascript, CSS, etc) files to multiple directories.

    Within the "PHPClasses" I have the PHP file "globalsLib.php". This file is "require_once" in couple of separate PHP scripts (say my main script, and then support scripts). Within the "globalsLib.php" I have the useful function "__autoload" defined, useful in automatically finding PHP files having the name of the classes that are contained in them. Now say that the main script and one or more of the support scripts ALSO included in the main script all have require_once("globalsLib.php"). What is happening is an error now:

    The error is:

    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

    There is ONLY ONE real globalsLib.php file, although it is pointed to by a real path and a symbolic path. Notice that even the line numbers are different, although they should be the same. Using my text editor (RJ Text Ed), I have opened the globalsLib.php file through the symbolic and real path, and the function is defined on the same line numbers.

    Again the question is: what are best practices for eliminating this potential mismanagement?
    Last edited by seniseven; 07-21-2012 at 06:18 AM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,330
    Maybe use realpath()?
    PHP Code:
    require_once(realpath($path)); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jul 2010
    Posts
    66
    I was kinda thinking something along those lines at one point.

    Then I was thinking that perhaps the "Best Practices" advice to me would be to keep the Development tree absolutely separate from the In-Use tree, and not to use symbolically linked directories at all.

    Thus when I make changes to included/support scripts, and everything is working on that side, then it gets copied over.

    I don't do this professionally, so I imagine someone who earns his living has figured out what do, especially if he had been stressed by being confronted with this situation.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles