Skip to content

Commit

Permalink
Make Zend_Validate_Date work as expected under PHP8.0
Browse files Browse the repository at this point in the history
By additionally catching an error where only an exception used to be
caught and thus returning false on Zend_Validate_Date::isValid the
validator now behaves the same under PHP8+
This also means that we don't need to catch the error in the test method
anymore.
  • Loading branch information
Alexander Wozniak committed Feb 5, 2021
1 parent 00dfa9e commit 897a31f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/zend-validate/library/Zend/Validate/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ private function _checkFormat($value)
} catch (Exception $e) {
// Date can not be parsed
return false;
} catch (Error $e) {
return false;
}

if (((strpos($this->_format, 'Y') !== false) or (strpos($this->_format, 'y') !== false)) and
Expand Down
6 changes: 1 addition & 5 deletions tests/Zend/Validate/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,7 @@ public function testLocaleContructor()
*/
public function testNonStringValidation()
{
try {
$this->assertFalse($this->_validator->isValid(array(1 => 1)));
} catch (Error $e) {
$this->assertTrue($e instanceof TypeError);
}
$this->assertFalse($this->_validator->isValid(array(1 => 1)));
}

/**
Expand Down

0 comments on commit 897a31f

Please sign in to comment.