Static Public Member Functions | |
static | isEmpty ($var=null) |
Check if a variable is empty. | |
static | import ($varName, $from, $default="") |
Bring the value of variable into the current scope. |
Various variable manipulation and checking class.
Definition at line 178 of file tlib.php.
static TLVars::import | ( | $ | varName, | |
$ | from, | |||
$ | default = "" | |||
) | [static] |
Bring the value of variable into the current scope.
Use this function to bring the value of a variable from the client side/serverside into the current scope. This function tries to safely implement a kind of register_globals. You can set the priorities of the various import sources (POST, GET, etc) by changing the order of the contents of the $from parameter. Additionally, you can specify a default value which will be set if the variable wasn't found.
Example:
$language = import("language", "SCPG", "en"); setcookie("language", $language, time() + 86400);
The code above import the 'language' variables value. It first tries the session, then a cookie, then POST and GET data. If all fails, the default 'en' will be used. After that a cookie is set so the next time the user returns,the language is automatically loaded. The cookie can be overridden with GET or POST.
varName | (string) The name of the variable to import. | |
from | (string) Specifies the source from where to import the variable. I.e. cookies, GET, POST, etc. It should be in the form of s string containing one or more of the chars in 'SPGC'. Last char in the string overrides previous sources. | |
default | (string) When no value is found in sources, assign this value. |
static TLVars::isEmpty | ( | $ | var = null |
) | [static] |
Check if a variable is empty.
This does roughly the same as PHP's empty() function but works on indirect variables. That is, a variable returned from a function or method can't be used with PHP's empty() function. This method does.
$var | (mixed) Variable to check. |