Native PHP
Functions, variables and constants of the PHP language or extensions may be used directly inside the Scriptol code. Their scope is external, that means they are visible anywhere, in global, local or class scopes.
Variables
PHP variables must be declared "extern" for the compiler can manage correctly
their scope. Once a PHP variable is declared in such way, it may be used as
a Scriptol variable but become global. An "extern" statement must be put at
start of a source file, along with "include" ones. If another statement is
found before an extern or include one, the laters are not recognized by the
compiler and error messages are thrown.
The syntax is:
extern type identifier
Examples:
extern
array argv `
this array holds the command line extern int argc ` this is the number of elements in the command ... argv.display() ` displaying the content |
If the PHP type is "mixed", the "dyn" keyword must be used in Scriptol.
If the PHP type is "string", the Scriptol equivalent is "text".
Table of types and equivalent
PHP
|
Scriptol
|
mixed
string array |
dyn
text array or dict |
Functions
PHP functions are used directly by Scriptol programs. There is no control
of the arguments by the compiler. If you want the compiler performing controls
on PHP functions, you have to declare their interface with the "extern" keyword.
Examples | extern
array array_flip(array) extern text substr(text, int, int last = 0) ... array a2 = array_flip(a1) text a = "demo" print substr(a, 1, 1) print substr(a, 2) |
Displays: | >
d > mo |
Constants
A PHP constant is declared as a variable, with the "constant" modifier.
Example:
extern constant text PHP_VERSION
...
print PHP_VERSION
External files
You can include a PHP file into a Scriptol program. You just have to use
a PHP function:
require("myfile.PHP") or
require_once("myfile.PHP")
The argument of the function is not tested, nor is the include file compiled,
but you can use functions declared inside, and variables with the PHP format:
$name.
The "include" function of PHP can't be used from Scriptol because
include is a keyword.
List of builtins functions
Look at the table from the builtins chapter.