Browse Source

merged branch Seldaek/at_op (PR #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-08T17: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.
Fabien Potencier 13 năm trước cách đây
mục cha
commit
da0eaa63cc

+ 4 - 1
src/Symfony/Component/Finder/Comparator/DateComparator.php

@@ -32,7 +32,10 @@ class DateComparator extends Comparator
             throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a date test.', $test));
         }
 
-        if (false === $target = @strtotime($matches[2])) {
+        try {
+            $date = new \DateTime($matches[2]);
+            $target = $date->format('U');
+        } catch (\Exception $e) {
             throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2]));
         }