I have a class I am coding that will validate forms entered by users.
I have set up my class, but now I have a strange little problem i cannot explain or fix....
I keep getting an error that array_push must have an array as a parameter - but I do. I thought it had something to do with me using $this->arrayName as the argument in the function - array_push($this->arrayName,$value);
So I changed it to -
$arr = $this->arrayName;
array_push($arr,$value);
$this->arrayName = $arr;
It still complained that I need an array as an argument.
So I thought it was the way I was declaring the variables when the class is initialized BUT-
Instance variables are declared in the class like so -
class formValidator
{
var $fields;
var $values;
var $patterns;
var $errors;
...rest of class
And the constructor looks like this -
function __construct()
{
$fields = array();
$values = array();
$patterns = array();
$errors = array();
...rest of constructor stuff - too long to list here, but does absolutely nothing to the fields array
So far, the function has now evolved into this -
function add_field($longName,$fieldName,$required,$fieldType,$validationType,$size,$specialPattern)
{
$fieldArray = array("longName"=>"$longName","fieldName"=>"$fieldName","required"=>"$required","fieldType"=>"$fieldType","validationType"=>"$validationType","size"=>"$size","specialPattern"=>"$specialPattern");
array_push($this->fields,$fieldArray);
//$arr = $this->fields;
//array_push($arr,$fieldArray);
//$this->fields = $arr;
RETURN 1;
}//end add_field
I am showing my commented out code in case you want to see the history of what I have attempted.
What am I missing here?
-Tony