Reply to Re: The principle of include files in PHP, not as in C++

Your name:

Reply:


Posted by Jerry Stuckle on 10/21/07 14:06

Tim Roberts wrote:
> Jerry Stuckle <jstucklex@attglobal.net> wrote:
>
>> Tim Roberts wrote:
>>> You missed the point. ...
>>> PHP's rules are different. Not better, not worse. Just different.
>> No, you missed the point.
>>
>> Compilation is not the same as execution. When PHP is executed, it's
>> include statement works just alike any file operation in C/C++ when that
>> program is executed.
>>
>> Just because they are both "include" statements does not mean they are
>> the same. In PHP they are executed. In C/C++ they are handled by the
>> preprocessor. Completely different environment with completely
>> different results.
>
> Nonsense. The distinction between compilation and interpolation is
> entirely artificial. PHP can be compiled, just as C can be interpreted.
> We're talking about source files including other source files. The concept
> is the same. PHP has different rules from C. It's just that simple, and I
> don't know why you want to make it more complicated.
>

You're wrong. Compilation is done by the compiler, under the rules
defined for that program. Execution is done by the program, under rules
defined for that program.

In the case of the C #include statement, how it works is defined by the
preprocessor, using the -I compiler command line option. That option
defines the order in which libraries which are included at compilation
(actually pre-processing) time. And once the program is compiled, the
included files are no longer needed.

In PHP, include is an executable statement, just like echo is. The
statement is executed at run time, using options defined in the php.ini
file. Additionally, the included file must exist when the program is
executed.

As I said. The only thing they have in common is the word "include".
Their operation is quite different.

>> And you are incorrect. In C/C++, include files are relative to the list
>> of directories in the -I (INCLUDE) compiler option (which can also be
>> specified in some IDE's). And you can use absolute paths in #include
>> statements.
>
> I never denied that. However, I am NOT incorrect. The first place C and
> C++ look for an "included" file is in the directory of the file currently
> being scanned. If not found there, only then does the preprocessor move on
> to the -I list.
>
> If the #include uses angle brackets (i.e. <stdio.h>), THEN the current
> directory is skipped and it goes straight to the -I path.

That's because that is the way the preprocessor works.

But to say the rules are different is wrong. The rules of execution are
exactly the same for C and PHP programs. C programs never execute an
include statement - because the preprocessor has handled it.

However, C programs can deal with files, etc. And the operation when
they are executed is exactly the same as when a php script is executed.
C programs will look in the current directory for the file. PHP
programs will look in the current directory for the file.

In this way, PHP's include statement is much more closely related to C's
(and PHP's) fopen() call. Both are executed statements, and operate
similarly.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[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

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