Sign in to follow this  
Rankith

PHP Array and Class problem

Recommended Posts

Hi, I am having a problem using an array inside a class in php. Here is my class: class Errors{ private $errors = array(); private $numErrors; function __construct(){ $numErrors = 1; $errors[1] = 1; } function Failed($fieldIn){ if($errors[1]){ return 'true'; } else{ return 'false'; } } } however, when I go to test that. The Failed function returns false... What am I doing wrong there?

Share this post


Link to post
Share on other sites
private $errors = array();
private $numErrors;

is fine
but change all the rest of them to

$this->numErrors = 1;
$this->errors[1] = 1;

and

if($this->errors[1]){

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this