
January 18th, 2013, 11:31 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
  
Time spent in forums: 13 m 50 sec
Reputation Power: 0
|
|
|
PHP-OOP - 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:
Quote: | 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.
|