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
Within the directory "Z:\service.web.Root" is the real subdirectory "PHPClasses" (full path is "Z:\service.web.Root\PHPClasses")
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.
Maybe use realpath()?
"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
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.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)