0

I want to make an array that will contain error strings so that I can output them if their is an error on the form.

But I keep getting this error Cannot use [] for reading in anyone know how to make an array for this kind of thing?

This is a snippet of my code:

class users {
...
public $errors = array();



//VALIDATE THE USERS INFO
function setError($error) {
    $this->errors = $error[];
}
//check the passwords match
function checkPasswords($pass1, $pass2){
    if($pass1 !== $pass2) {
        setError("Your passwords dont match");
    } else {
        $this->password = $pass1;
    }
}

}

1 Answer 1

2

Almost there... the square brackets go on the left of the equals sign, so setError should be:

function setError($error) {
    $this->errors[] = $error;
}

Well that and in checkPasswords you should call setError as:

$this->setError("Your passwords don't match");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.