Hi!
I assume you want to obligate yourself to declare variables before they can be used?
For one thing, variable declarations are not used in PHP, it creates variables on the fly so you cannot do something like this (C++):
int i, k;
CString sUserName;
However, you do have to initialize an associative's array element before it can be used:
$page['test'] = "value";
print $page['test'];
However, even in this case you can set the error_reporting level a tad lower to ignore notices - and the interpreter will just print a null in this case.
If you need to force yourself to 'initialize' a variable, then use an associative array with error_reporting set to E_ALL. In this case the interpreter will warn you. But you will have worse speed in this case since all operations on associative arrays are done via key lookups, and key lookups with string keys are slower than key lookups when using integer keys.
Another alternative is using a class and making separate member variables you would have to initialize via class's member functions (because usually it's tough to remember member variables and methods seem as a better alternative).
class MyClass
{
var $var1;
function GetVar()
{
if (!$var1) print "Variable empty!";
return $this->var1;
}
function SetVar($newval) $this->var1 = $newval;
}
$myclass = new MyClass();
$var = $myclass->GetVar();
I hope this helps.
Best,
Stas