<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>PHP on Brad's Blog</title><link>https://blog.bjdean.id.au/tags/php/</link><description>Recent content in PHP on Brad's Blog</description><generator>Hugo -- 0.152.2</generator><language>en-au</language><copyright>Bradley Dean</copyright><lastBuildDate>Mon, 28 May 2018 09:01:25 +0000</lastBuildDate><atom:link href="https://blog.bjdean.id.au/tags/php/index.xml" rel="self" type="application/rss+xml"/><item><title>On the importance of reading the docs - PHP's date_parse errors</title><link>https://blog.bjdean.id.au/2018/05/on-the-importance-of-reading-the-docs-phps-date_parse-errors/</link><pubDate>Mon, 28 May 2018 09:01:25 +0000</pubDate><guid>https://blog.bjdean.id.au/2018/05/on-the-importance-of-reading-the-docs-phps-date_parse-errors/</guid><description>&lt;p&gt;It&amp;rsquo;s important to read the documentation, and then read it again once or twice.
PHP&amp;rsquo;s &lt;a href="http://php.net/manual/en/function.date-parse.php"&gt;date_parse&lt;/a&gt; function parses a datetime string and returns an &amp;ldquo;array with information about the parsed date on success or FALSE on failure.&amp;rdquo;
This makes it tempting to use the function something like:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$datetime = date_parse($datetime_string);
if ( $datetime === FALSE ) {
# Failure - deal with the bad $datetime_string
}
else {
# Success - use the $datetime
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;However&lt;/strong&gt; in this case failure means the the date_parse function has failed to work at a fairly fundamental level and reading the docs further you find &amp;ldquo;In case the date format has an error, the element &amp;rsquo;errors&amp;rsquo; will contains the error messages.&amp;rdquo;
And indeed:&lt;/p&gt;</description></item></channel></rss>