• Advertisement
Sign in to follow this  

PHP Array and Class problem

This topic is 4369 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement