Variables

Variables can store the following types of data:
·string;  
·number (int/double);  
·true/false;  
·hash (associative array);  
·class of objects;  
·object of a class (user-defined class as well);  
·code;  
·expression.  

To use a variable, you don't have to declare it in advance.

Different types of data demand different brackets to be used while a variable is assigned:

$variable_name[string]
assigns a string (an object of class string) or an object of some class;
$variable_name(expression)
assigns a number or result of some mathematical expression
$variable_name{code}
assigns some code to be executed when the variable is referred to


To retrieve value stored in a variable, you should refer to the variable by name:

$variable_name-retrieves value stored in variable

Examples
Code
Result
$string[2+2]
$string 

2+2
$number(2*2)
$number


4

$i(0)
$code{$i}
$i(1)
$code

1
$i(0)
$string[$i]
$i(1)
$string

0


As a part of variable's name you may use:


...value stored in another variable:
$superman[value of superman variable]
$part[man]
$super$part
will return: value of superman variable

$name[picture]
${name}.gif
will return string picture.gif (but NOT field gif of object picture)

...result of some code:

$field.[b^eval(2+3)]
will return field b5 of object field.


Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 04.09.2008