8000 merged branch Seldaek/at_op (PR #3837) · phreaknerd/symfony@da0eaa6 · GitHub
[go: up one dir, main page]

Skip to content

Commit da0eaa6

Browse files
committed
merged branch Seldaek/at_op (PR symfony#3837)
Commits ------- f3408cc [Finder] Avoid unnecessary use of the @ operator Discussion ---------- [Finder] Avoid unnecessary use of the @ operator Tests are passing --------------------------------------------------------------------------- by stof at 2012-04-08T17:42:01Z Does PHP really throw an exception on failure or is it only the case when an error handler converts a warning to an exception ? It would be weird given the small amount of cases where PHP uses exceptions. --------------------------------------------------------------------------- by Seldaek at 2012-04-08T1 8000 7:43:51Z ``` $ php -r 'new DateTime("foo");' Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database' in Command line code on line 1 ``` --------------------------------------------------------------------------- by Seldaek at 2012-04-08T17:45:09Z In a constructor it's pretty hard to return false, so it has to throw an exception. The php.net docs also say it so I'm fairly sure it's nothing specific to my setup.
2 parents 27c41f1 + f3408cc commit da0eaa6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Symfony/Component/Finder/Comparator/DateComparator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public function __construct($test)
3232
throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a date test.', $test));
3333
}
3434

35-
if (false === $target = @strtotime($matches[2])) {
35+
try {
36+
$date = new \DateTime($matches[2]);
37+
$target = $date->format('U');
38+
} catch (\Exception $e) {
3639
throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2]));
3740
}
3841

0 commit comments

Comments
 (0)
0