View Single Post
  #3 (permalink)  
Old 04-21-2008, 06:57 PM
Chiefos Chiefos is offline
WebProWorld New Member
 

Join Date: May 2006
Posts: 10
Chiefos RepRank 0
Default Re: Function to load vars in PHP?

Callme I think what your after is a means of setting a buch of variables and having methods appropriate to these vars without having the variables declared gloabally (Note that when I say globally I dont mean in the $_globals array but globally within the variable scope of the page).

Basically what I think you need to look at is a little basic OOP, here you can declare properties which are only avaliable in the scope of that object instance so in your case:

N.B. Its been a while since ive done php so syntax may be wrong:

<?php

class SomeClassWithVariablesToValidate
{
$Var, $Varb, $Varc;

public __Construct()
{
$this->ResetVariables();
}
public ResetVariables()
{
$this->Var = 0;
$this->Varb = 1;
$this->Varc = 2;
}
public Validate()
{
if($this->Var!=null && this->Varb!=null && this->Varc!=null )
return true;

return false;
}
}


//Test usage
$pointlessClass = new SomeClassWithVariablesToValidate();

if($pointlessClass->Validate())
echo "Validated";
?>
Reply With Quote