Reply to Re: require_once() and Subdirectories

Your name:

Reply:


Posted by Rik on 06/07/07 16:02

On Thu, 07 Jun 2007 17:45:49 +0200, David T. Ashley <dta@e3ft.com> wrote:
>>> Does require_once() treat "file.inc" and "subdirectory/file.inc" as the
>>> same
>>> things or different?
>>
>> Different, obviously, it searches another directory for the file instead
>> of the current working directory.
>>
>>> The reason for my question is that I'd like to organize my PHP library
>>> into
>>> subdirectories, and if I accidentally have a naming collision, I'm
>>> curious
>>> how require_once() will behave.
>>
>> It recognizes the exact file you use (how else could PHP actually open
>> the
>> included/required file?). So no matter how much files are named
>> 'class.php' or 'index.php', each will be recognised as different in
>> their
>> respective directory.
>>
>> So to answer the real question: you can divide your library into
>> different
>> directories all you like, files in different directories with the same
>> name do not bother the include(_once())/require(_once()) functions.
>>
>> The only caveat is the if you're used to working with (and are depending
>> on) a standard include_dir, you might get some unexpected results
>
> Thanks for your reply.
>
> My question was subtly different.

No, it wasn't.

> I have no doubt that require_once() will open and include the correct
> file.
>
> I was concerned about it possibly believing that "/dir1/file.inc" had
> been
> included when it was "/dir2/file.inc". In other words, I was concerned
> about the "once" part of it and how it remembers what has already been
> included.
>
> My question was about the "once" part of it.

Which was answered by "It recognizes the exact file you use (...) So no
matter how much files are named 'class.php' or 'index.php', each will be
recognised as different in their respective directory.".

You tell me how that could be any clearer?

If you use get_included_files(), you'd see PHP stores the full path of all
files, not just the filename.
--
Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация