From: evert at rooftopsolutions dot nl
Operating system: Any
PHP version: 5.5.15
Package: Date/time related
Bug Type: Bug
Bug description:DateTimeZone and DateTime constructors log php warnings when they shouldn't.
Description:
------------
When creating new DateTime or DateTimeZone objects, we catch exceptions
to ensure ensure that we handle invalid strings.
Despite that, warnings still make their way into the error log.
I don't think we have a way to surpress these errors, as the silence (@)
operator also doesn't seem work for this case.
Test script:
---------------
<?php
try {
$dt = new DateTimeZone('Twilight zone');
} catch (\Exception $e) {
echo "Caught: " . $e->getMessage() . "\n";
}
print_r(error_get_last());
try {
$dt = new DateTime('Foo-Bar');
} catch (\Exception $e) {
echo "Caught: " . $e->getMessage() . "\n";
}
print_r(error_get_last());
Expected result:
----------------
Caught: DateTimeZone::__construct(): Unknown or bad timezone (Twilight
zone)
Caught: DateTime::__construct(): Failed to parse time string (Foobar) at
position 0 (F): The timezone could not be found in the database
Actual result:
--------------
Caught: DateTimeZone::__construct(): Unknown or bad timezone (Twilight
zone)
Array
(
[type] => 2
[message] => DateTimeZone::__construct(): Unknown or bad timezone
(Twilight zone)
[file] => /Users/evert/code/phpbug/foo.php
[line] => 4
)
Caught: DateTime::__construct(): Failed to parse time string (Foobar) at
position 0 (F): The timezone could not be found in the database
Array
(
[type] => 2
[message] => DateTime::__construct(): Failed to parse time string
(Foobar) at position 0 (F): The timezone could not be found in the
database
[file] => /Users/evert/code/phpbug/foo.php
[line] => 12
)
--
Edit bug report at https://bugs.php.net/bug.php?id=67881&edit=1
--