PHP Warning in Magento 2 "Warning: A non-numeric value encountered"

PHP Warning in Magento 2 "Warning: A non-numeric value encountered"

October 15, 2026 · Illustrated author avatarBy Stefan Bogdanescu
PHP Warning in Magento 2 "Warning: A non-numeric value encountered"

Resolving PHP Warnings in Magento 2: A Comprehensive Guide

Are you facing a “Warning: A non-numeric value encountered” error while working with your Magento 2 store? You’re not alone. This common warning can stem from various sources, but we’ll drill down to the root cause and provide a step-by-step solution.

Understanding the Error Context

The provided code snippet suggests that the warning originates from an extension’s file, particularly at line 336:

$this->lastPageFooterHeight = $footerHeight + $elementGroupHeight;

At first glance, this line appears to be adding two numerical values together. However, the warning implies that one or both of these variables might not actually be numeric.

The Potential Causes

Incorrect Variable Type

The most likely culprit is a mismatch between what you expect and what PHP actually sees. Even though you’re anticipating numerical values for $footerHeight and $elementGroupHeight, they might contain empty strings, null values, or even non-string data types that can’t be numerically compared.

PHP Version Compatibility

As you mentioned in your research, the PHP version could potentially contribute to this issue. While the error message seems universal, some extensions or specific Magento configurations may interact differently with PHP 7.3 compared to earlier versions. This is worth considering if you’ve recently updated your PHP environment.

Step-by-Step Resolution

1. Verify Variable Types

Inspect the values of $footerHeight and $elementGroupHeight before the addition operation:

echo "Footer Height: " . gettype($footerHeight) . "<br>";
echo "Element Group Height: " . gettype($elementGroupHeight) . "<br>";

This will print out the data type for each variable, helping you validate whether they are indeed numeric or if there’s a mismatch.

2. Use Type Checking

If one of the variables is not a number, you can use PHP’s is_numeric function to ensure only numerical values are processed:

$this->lastPageFooterHeight = (is_numeric($footerHeight) ? $footerHeight : 0)
                             + (is_numeric($elementGroupHeight) ? $elementGroupHeight : 0);

This code uses the ternary operator to replace any non-numeric value with a default of zero before performing the addition.

3. Review Extension Configuration

If the issue persists, it might be due to specific Magento extension configurations or third-party integration issues. Check for any customizations or recent updates that could have introduced the problem.

Best Practices for Handling Warnings

As a general best practice, always strive to eliminate warnings in your production environment. Warnings don’t necessarily break functionality, but they can indicate potential issues and degrade performance over time.

To manage warnings effectively:

  1. Establish a clear warning suppression policy.
  2. Use try-catch structures around potentially problematic code.
  3. Implement logging mechanisms to track recurring warnings.

Conclusion

The “Warning: A non-numeric value encountered” error in Magento 2 is often caused by type mismatches or extension configuration issues. By verifying variable types and implementing proper type checking, you can effectively resolve this warning.

Remember, while warnings don’t always stop your store from functioning, they can signal underlying problems that may lead to more serious issues down the line. It’s crucial to address them promptly for optimal performance and security.

For a broader perspective on PHP development best practices and Magento extensions, I recommend exploring our comprehensive guides at LaravelCompany.

Magento 2 Extensions Configuration Errors

Our network