Re: [PHP] HELP: Nested include(...)'s take relative paths not intuitively
Hi there again people, I looks like this thread turned into a 'include' usage discussion. Well, nothing wrong with that. The conclusion seems to be that ALL level of nested included inherit current directory reference for relative paths from the very first script ( that in $_SERVER[SCRIPT_NAME] ) that calls them. I just wanted to clarify my need, even I know some one may think it is not a good idea to depend in nested includes in higher level subdirs for default/inherited script behaviour. I came to this question when trying to design a framework for my personal site with the following requirements. 1. Full frame integration (for frame I mean same menu, links, etc.. around the content of a specific seccion, no the html frame tag) 2. Full modularity of subseccions, it means to me, put a subseccion in a subdirectory an it should be ready to go. Of course I need to make some includes standar for this to work. All this is cleanly implemented with includes for inherited defaults up to 1 level of subseccion depth. Since I want second-level-depth (or subsubseccions) not to know about what is above them, I came to need this NESTED includes and that is where all started to fall apart with the problem I already described. I will start looking for a diferent aproach. Thanxs to u all. __ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HELP: Nested include(...)'s take relative paths not intuitively
Hello Samuel, Tuesday, February 10, 2004, 6:55:24 PM, you wrote: SV I have 3 files in nested subdirectories [snip] SV Is this a bug or a feature? Neither, it's just logic really. The include() function sucks in the file specified, dropping out to HTML mode to do so. The included file inherits all of the properties of the one that included it, such as current directory location, variable scope, etc. The include function doesn't (and cannot) know you're including more PHP code. In short, never mess around with ../ in a directory of an include file, that's pretty bad structure anyway IMHO. -- Best regards, Richardmailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HELP: Nested include(...)'s take relative paths not intuitively
From: Samuel Ventura [EMAIL PROTECTED] I have 3 files in nested subdirectories (1) /test.php (2) /subdir1/test.php (3) /subdir1/subdir2/test.php if I call (3) it loops forever in (2) trying to including itself. Is this a bug or a feature? A feature? You make a request for (3). The thing to remember/realize is that now all require(), include(), etc. calls now happen relative to the path of (3). So, when you include (2), which tries to include ../test.php, it is trying to include itself again because the include() happens relative to the path of (3). include()'s are almost like a cut and paste. If you took the code from (2) and pasted it into (3) in place of the include(), that's the end result. This is why I do not use relative paths. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HELP: Nested include(...)'s take relative paths not intuitively
From: Alex Hogan [EMAIL PROTECTED] Are you saying that it's better not to use relative paths on include(...)'s, require(...)'s and their (x)_once(...) cousins? That seems awkward to me. Why would I want to hard code a path, even if I was including additional functionality from another file? Use whatever you're comfortable with because they both work. I'm just saying that I stay away from relative includes, myself. It's easy to just create a variable (or extract the data from $_SERVER) to find out the absolute path and just use that as a variable. Then you can do this: include($_CONF['path'] . '/test.php'); for example. I make similar $_CONF variables for the html root of the site $_CONF['html'] = 'http://www.bigredspark.com'; so that even the links in my html are full URLs instead of relative links. To each his own. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HELP: Nested include(...)'s take relative paths not intuitively
Richard Davey wrote: include $dir/file.php vs. include($dir/file.php) Both work just fine. The manual includes examples of both methods. So which do most people consider the right way ? If you use echo, then you should use include(). If you use print, then you should use include . Unless you use echo(), then you should use include and if you use print , then you should use include(). Unless you don't want to. :) Like someone else said: Personal preference. There's no right or wrong. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HELP: Nested include(...)'s take relative paths not intuitively
On Wed, 2004-02-11 at 19:36, John W. Holmes wrote: If you use echo, then you should use include(). If you use print, then you should use include . Unless you use echo(), then you should use include and if you use print , then you should use include(). Unless you don't want to. :) Heh, what if I use print('')? :P Actually, I use echo(''), even though using single quotes doesn't give me better performance I like to separate my strings and variables. I enjoy using echo, it's like a rebellion against printf. -- Adam Bregenzer [EMAIL PROTECTED] http://adam.bregenzer.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php