...

View Full Version : Array as Data Memeber in OOP



srule_
12-26-2007, 10:06 PM
How do you make a data memeber an array? In the following example i would like "errors" to be an array:



class Register {

//Data Memeber
private $username;
private $email;
private $password;
private $errors; //Need This To Be An ARRAY

//Contructor Function
public function __construct(){
$this->username = '';
$this->email = '';
$this->password = '';
$this->errors = '';
}


//--------------------------------------------------------------
//Check Username
public function checkUsername() {
if (empty($_POST['username']))
{
$this->errors = 'You forgot to enter your first name.';
}
elseif (strlen($_POST['username']) <2 OR strlen($_POST['username']) >13 )
{
$this->errors = 'Your username must be between 3 and 12 characters';
}
else
{
$this->username = $_POST['username'];
}
}

Inigoesdr
12-26-2007, 10:19 PM
private $errors = array();

hammer65
12-26-2007, 11:17 PM
But in your constructor, if you re-initialize it to be a string, then it will no longer be an array.

srule_
12-26-2007, 11:27 PM
ok thanks,

and how would I give values to this array in my code?

Inigoesdr
12-26-2007, 11:32 PM
$this->errors[] = 'Error message';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum