Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts

    Array as Data Memeber in OOP

    How do you make a data memeber an array? In the following example i would like "errors" to be an array:

    PHP Code:
    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']) <OR strlen($_POST['username']) >13 )
                {
                
    $this->errors 'Your username must be between 3 and 12 characters';
                }
                    else
                    {
                    
    $this->username $_POST['username'];
                    }
        } 

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    PHP Code:
    private $errors = array(); 

  • #3
    Regular Coder
    Join Date
    Dec 2007
    Location
    Nebraska
    Posts
    113
    Thanks
    0
    Thanked 2 Times in 2 Posts
    But in your constructor, if you re-initialize it to be a string, then it will no longer be an array.
    Deliver yesterday, code today, think tomorrow.

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts
    ok thanks,

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

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    PHP Code:
    $this->errors[] = 'Error message'


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •