TLVars Class Reference

Variable manipulation and tool class. More...

List of all members.

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.


Detailed Description

Variable manipulation and tool class.

Various variable manipulation and checking class.

Definition at line 178 of file tlib.php.


Member Function Documentation

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.

Parameters:
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.
Precondition:
Use of 'S' in From requires session_start() to already be called
Returns:
Contents of the variable as gotten from the last valid source described by $From. If VarName was not found in any of the specified sources, this function returns 'undefined', and the the var to which assignment is done should also be undefined.
Note:
The behaviour of an assignment from a function which doesn't return anything is not specified I believe. Results may vary.

Definition at line 228 of file tlib.php.

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.

Parameters:
$var (mixed) Variable to check.
Returns:
True if $var is 'empty'. "", null, false, 0 and an empty array are considered empty (strict type checking is enforced (===)). False if not empty.
Note:
To supress 'Undefined variable' errors, you should prepend the call to this method with an '@'.

Definition at line 191 of file tlib.php.


The documentation for this class was generated from the following file:
Generated on Sun Sep 24 22:05:25 2006 for TLib-PHP by  doxygen 1.4.7