[PR #495] [CLOSED] Fix spurious E_WARNING being emitted from date_default_timezone_get(). #1185

Closed
opened 2026-03-04 03:06:31 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Seldaek/monolog/pull/495
Author: @jchesterpivotal
Created: 1/14/2015
Status: Closed

Base: masterHead: fix-datetime-warning


📝 Commits (1)

  • f0ded6b Fix spurious E_WARNING being emitted from date_default_timezone_get().

📊 Changes

1 file changed (+4 additions, -0 deletions)

View changed files

📝 src/Monolog/Logger.php (+4 -0)

📄 Description

Other packages relying on Monolog will sometimes interpret E_WARNINGs as exceptions, causing
them to fail. The usual advice is to edit php.ini to set the date.timezone setting. But this
approach requires turning every development workstation into a snowflake. Instead, we follow
the lead of other projects and introduce this snippet to modify the default PHP behaviour.

Normally, we would provide a test case to demonstrate that the E_WARNING is no longer
emitted from Monolog. However we could not find a way to test this behaviour. To start with,
multiple sites in the test code (both PHPUnit and the Monolog bootstrap.php) will either
use ini_set() on date.timezone, or date_default_timezone_set(), to set the timezone to UTC.
Once this is done, the E_WARNING is never emitted again. Then, if we try to use ini_set()
or ini_restore() in the test, PHP either rejects (ini_set) or ignores (ini_restore) our
attempt to recreate the default conditions which lead to this problem. There may be a way
to test this, but we are not aware of one.

The snippet included here, or similar snippets, appears widely in the PHP universe. An
identical snippet appears in Composer[1] and semantically identical code has been baked
into phpBB[2] and Mediawiki[3], amongst others that we found while searching.

In an ideal world, the PHP interpreter would stop emitting the E_WARNING. UTC is a sane
default value for timezone settings, and users who required a different setting would
be motivated to find the mechanism for changing it, leaving the common case unpunished.
However, it seems that this is unlikely to occur[4]. Hence, this patch is required to
work around the shortcomings of PHP.

[1] github.com/composer/composer@e5ecad7eeb
[2] https://tracker.phpbb.com/browse/PHPBB3-7729
[3] http://git.wikimedia.org/commit/mediawiki%2Fcore.git/8e41f42b67cec4a6256080aea8a89c9e5b0ceb05
[4] http://www.serverphorums.com/read.php?7,712151


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Seldaek/monolog/pull/495 **Author:** [@jchesterpivotal](https://github.com/jchesterpivotal) **Created:** 1/14/2015 **Status:** ❌ Closed **Base:** `master` ← **Head:** `fix-datetime-warning` --- ### 📝 Commits (1) - [`f0ded6b`](https://github.com/Seldaek/monolog/commit/f0ded6b4c0012faff99f79af57729d90b1a65572) Fix spurious E_WARNING being emitted from date_default_timezone_get(). ### 📊 Changes **1 file changed** (+4 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/Monolog/Logger.php` (+4 -0) </details> ### 📄 Description Other packages relying on Monolog will sometimes interpret E_WARNINGs as exceptions, causing them to fail. The usual advice is to edit php.ini to set the date.timezone setting. But this approach requires turning every development workstation into a snowflake. Instead, we follow the lead of other projects and introduce this snippet to modify the default PHP behaviour. Normally, we would provide a test case to demonstrate that the E_WARNING is no longer emitted from Monolog. However we could not find a way to test this behaviour. To start with, multiple sites in the test code (both PHPUnit and the Monolog bootstrap.php) will either use ini_set() on date.timezone, or date_default_timezone_set(), to set the timezone to UTC. Once this is done, the E_WARNING is never emitted again. Then, if we try to use ini_set() or ini_restore() in the test, PHP either rejects (ini_set) or ignores (ini_restore) our attempt to recreate the default conditions which lead to this problem. There may be a way to test this, but we are not aware of one. The snippet included here, or similar snippets, appears widely in the PHP universe. An identical snippet appears in Composer[1] and semantically identical code has been baked into phpBB[2] and Mediawiki[3], amongst others that we found while searching. In an ideal world, the PHP interpreter would stop emitting the E_WARNING. UTC is a sane default value for timezone settings, and users who required a different setting would be motivated to find the mechanism for changing it, leaving the common case unpunished. However, it seems that this is unlikely to occur[4]. Hence, this patch is required to work around the shortcomings of PHP. [1] https://github.com/composer/composer/commit/e5ecad7eeb035e7579e5cc729b46412188ebb2ae [2] https://tracker.phpbb.com/browse/PHPBB3-7729 [3] http://git.wikimedia.org/commit/mediawiki%2Fcore.git/8e41f42b67cec4a6256080aea8a89c9e5b0ceb05 [4] http://www.serverphorums.com/read.php?7,712151 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-04 03:06:31 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#1185
No description provided.