#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Fatal error: Cannot redeclare class AbstractClass


    I have an abstract class:

    Code:
    abstract class BaseValidator{
    	protected $msgs = array();
    	protected $params = array();
    	
    	abstract protected function isValid($value);
    	
    	public function __contruct($_params){
    		$this->params = $_params;
    	}
    	
    	public function getMessages(){
    		return $this->msgs;
    	}
    	
    }

    I have some classes extending this class:

    Code:
    <?php
    require 'BaseValidator.php';
    
    class PasswordValidator extends BaseValidator{
    	public function isValid($val=null){
    		if($val == null){
    			$val = $this->params['value'];
    		}
    		
    		if(strlen($val)<$this->params['minlength']){
    			array_push($msgs, 'Password length is too short. Password must be at least 8 characters.');
    		}
    		
    		if(!StringUtil::isAlphabetic($val)){
    			array_push($msgs, 'Password can only contain characters in the alphabet. No special characters (@#$%^&*()!) are allowed.');
    		}
    		
    		return count($this->msgs) > 0 ? false : true;
    	}
    }
    ?>
    I have a form processing page that uses them:

    Code:
    $passwordValidationObject = new PasswordValidator(array('minlength'=>6,'value'=>$password,'required'=>true));
    	if(!$passwordValidationObject->isValid()){
    		echo implode('<br/>',$passwordValidationObject->getMessages());
    	}
    I keep getting this error:
    Fatal error: Cannot redeclare class BaseValidator in BaseValidator.php on line 4
    how can i get around this error?
    If I remove the require_once BaseValidator, of course, it doesn't work either.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0
    the problem was I had to use require_once!

    Comments on this post

    • ManiacDan agrees : Yep

IMN logo majestic logo threadwatch logo seochat tools logo