{"id":9067558,"date":"2017-04-25T21:39:45","date_gmt":"2017-04-25T21:39:45","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/php-fatal-error-uncaught-exception-datetime__construct\/"},"modified":"2017-04-25T21:39:45","modified_gmt":"2017-04-25T21:39:45","slug":"php-fatal-error-uncaught-exception-datetime__construct","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/php-fatal-error-uncaught-exception-datetime__construct\/","title":{"rendered":"PHP Fatal error: Uncaught Exception: DateTime::__construct()"},"content":{"rendered":"<p>The plugin was throwing this error:<\/p>\n<p><em>PHP Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (9 marzo, 2017) at position 5 (z): The timezone could not be found in the database in \/httpdocs\/wp-content\/plugins\/cache-control\/cache-control.php:191<\/em><\/p>\n<p><strong>The page was returning a HTTP 500 Internal server error showing the white screen of death.<\/strong><\/p>\n<p>At cache-control.php line 191, i have seen:<\/p>\n<p> <code>$date_mod = new DateTime( get_the_modified_date() );<\/code><\/p>\n<p>A date object is created from the string retrieved by get_the_modified_date()<\/p>\n<p>At wordpress codex we can read that get_the_modified_date( $d, $post ) returns (string) the date on which the post was last modified. The function parameters are both optional and $d in particular is (string) (optional) Optional PHP date format. Defaults to the &#8220;date_format&#8221; option.<\/p>\n<p>My wordpress installation is in Spanish and the date_format option is by default j F, Y. The date string retrieved by get_the_modified_date is not valid to create a new DateTime object.<\/p>\n<p>To ensure that the $date_mod DateTime object is correctly created for any possible date_format option value, i have changed the line to this:<\/p>\n<p><code>$date_mod = new DateTime( get_the_modified_date( &#039;Y-m-d&#039; ) );<\/code><\/p>\n<p>That way we ensure that the value retrived by get_the_modified_date is alwais going to be correct to create the $date_mod DateTime object no matter the date_format option value. <\/p>\n<p>Here is the patch to fix the issue:<\/p>\n<pre><code>Index: trunk\/cache-control.php\n===================================================================\n--- trunk\/cache-control.php\t(revision 1645039)\n+++ trunk\/cache-control.php\t(working copy)\n@@ -205,7 +205,7 @@\n \n     if ( $option_name == &#039;singles&#039; &amp;&amp; get_option( &#039;cache_control_singles_mmulti&#039; ) == 1 ) {\n         $date_now = new DateTime();\n-        $date_mod = new DateTime( get_the_modified_date() );\n+        $date_mod = new DateTime( get_the_modified_date( &#039;Y-m-d&#039; ) );\n \n         $last_com = get_comments( &#039;post_id=&#039; . get_the_ID() . &#039;&amp;number=1&amp;include_unapproved=1&amp;number=1&amp;orderby=comment_date&#039; );\n         if ( $last_com != NULL ) {<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-9067558","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/9067558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/9067558\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=9067558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}