Customers with an empty Date of Birth cannot be saved

A core Magento bug that developers are stumbling across recently is the issue involving records involving customers with an empty Date of Birth cannot be saved in the admin.

When attempting to save a customer within the admin, and having not filled out the optional Date of Birth field may result in the following error message showing.

Customers with an empty Date of Birth cannot be saved

Looking in Magento’s system.log file, the following log entry appears.

main.CRITICAL: Exception message: Warning: A non-numeric value encountered in /var/www/html/magento/vendor/magento/zendframework1/library/Zend/Locale/Math/PhpMath.php on line 94

This error has been occurring on Magento Open Source version 2.2.1 with PHP version 7.1.1, although there have been reports of the issue on different combinations of Magento and PHP versions.

Fortunately, there is a fix available despite a fix from the core Magento team not yet implemented in the most recent release.

A fix available can be seen on Magento’s Github page, located here: https://github.com/magento/magento2/commit/4801d7486e16f200beede7a9afddb0d23cc1ec51.

In order to apply the fix to current Magento versions, it is not feasible to directly edit the core Magento Framework file.

Instead, use the Composer Patches package as posted about in more detail here.

Below is a patch that will resolve the issue.

--- ../vendor/magento/framework/Data/Form/Filter/Date.php	2018-04-23 15:32:13.000000000 +0100
+++ ../vendor/magento/framework/Data/Form/Filter/Date.php	2018-04-23 15:32:02.000000000 +0100
@@ -54,6 +54,10 @@
      */
     public function inputFilter($value)
     {
+        if (!$value) {
+            return $value;
+        }
+
         $filterInput = new \Zend_Filter_LocalizedToNormalized(
             ['date_format' => $this->_dateFormat, 'locale' => $this->localeResolver->getLocale()]
         );
@@ -74,6 +78,10 @@
      */
     public function outputFilter($value)
     {
+        if (!$value) {
+            return $value;
+        }
+
         $filterInput = new \Zend_Filter_LocalizedToNormalized(
             ['date_format' => DateTime::DATE_INTERNAL_FORMAT, 'locale' => $this->localeResolver->getLocale()]
         );

In the above example, the patch file, 12302.patch is added to a vendor_patches directory located in the Magento 2 root directory.

In the Magento 2 composer.json file, add the patch to the patches configuration within extra.

"extra": {
    "patches": {
        "magento/framework": {
            "[PATCH]: Fixed 'Non-numeric value' warning on account create/save when DOB field is visible #12302": "vendor_patches/12302.patch"
        }
    }
}

Now when the composer install command is run, the patch is applied on top of the magento/framework package, seamlessly implementing the fix.

Note: This article is based on Magento Open Source version 2.2.