I have a problem with the code and don’t know what to do.
I used this
$validate = new OOP_Validate;
$validate->addValidator(new OOP_Validate_Int());
if($validate->isValid('test')) echo 'TRUE';
and show me error:
Catchable fatal error: Argument 1 passed to OOP_Validate::addValidator() must implement interface OOP_Validate_Interface, instance of OOP_Validate_Int given, called in C:\xampp\htdocs\GameV\index.php on line 21 and defined in C:\xampp\htdocs\GameV\library\OOP\Validate.php on line 37
AddValidator:
public function addValidator(OOP_Validate_Interface $validator, $breakChain = false){
$this->_validators[] = array(
'Name' => $validator,
'Break' => $breakChain,
);
return $this;
}
Interface:
interface OOP_Validate_Interface {
public function isValid($value);
public function getMessage();
}
What could be wrong?
As the error message explains, the
addValidatormethod requires that the first argument passed to it implements the interface calledOOP_Validate_Interface.Check your code and change the class declaration for
OOP_Validate_Intto be:For more info, check the Object Interface section in the PHP manual.