Next: Semantic Differences, Previous: INI File Entries, Up: Differences Between Roadsend And Zend PHP
PHP provides a method for including code from other source files into
a single source file through the include
, require
,
include_once
and require_once
functions. In Open Source
PHP, this always happens at runtime as each script is interpreted.
The include functionality changes slightly when compiling a source file into an executable (or library), however.
At compile time, if Roadsend PHP encounters one of the include
functions, it will attempt to find the source file to be included
(searching the current INCLUDE_PATH) for inclusion in the build. If it
finds the file, that file will also be compiled and will be included
as part of the resulting binary (or library).
If the file was not found, however, it is not a fatal error. When the compiled code is run, the file to be included will be searched for at runtime (based on the current runtime INCLUDE_PATH), and if found will be interpreted on the fly. While this may be convenient and useful in some situations, please keep in mind that interpreting code at runtime is always slower than compiling the code into the binary.
If your program uses variables to name include files, for example:
include($proj . "/foo.php");
, then the compiler may be unable
to automatically compile those files into your program. You can add
the files manually by listing them on the compile commandline after
your main file, for example pcc myprog.php project/foo.php
, or
by adding the include files to your project in the Roadsend IDE.
The Roadsend Compiler provides a new PHP function,
lib_include_exists()
, which can be used to determine whether
the compiled or interpreted version of an include file is being used.
Simply call it with the name of the file, as you would call
include()
. It returns true if the compiled version of the
include file was found, and false if not.