Fatal error: Call to undefined function money_format()

Fatal error: Call to undefined function money_format()

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Fatal error: Call to undefined function money_format()

You are encountering a Fatal error because the PHP function money_format() is no longer available in your current environment. This specific error usually surfaces when running code written for older versions of PHP (specifically PHP 5) on modern servers running PHP 7, 8, or later.

The root cause is that money_format() was deprecated and eventually removed. The function was originally part of the C standard library's POSIX interface, but it suffered from several significant design flaws that led to its removal in favor of more robust alternatives. Specifically, the function behaved inconsistently across different operating systems and locales. On some systems, it would add an extra character to the formatted string depending on whether the locale was set, making it unpredictable for web applications that need strict output consistency. Furthermore, it lacked support for formatting currency symbols directly within the format mask, requiring developers to rely on system-specific locale settings to get the dollar sign or Euro symbol correct.

When you see Call to undefined function money_format(), your PHP interpreter is explicitly telling you that this legacy tool has been discarded. It is not a configuration error where you simply forgot to load a library; the function physically does not exist in the active runtime.

To resolve this, you must migrate your formatting logic to number_format(). This built-in PHP function provides precise control over decimal places and thousands separators without relying on external locale files or risking platform-specific inconsistencies.

Here is how to refactor the problematic lines from your code snippet:

// Old approach (Deprecated/Removed)
// $pricetotal = money_format("%10.2n", $pricetotal);

// New approach (Modern PHP Standard)
$currencySymbol = '$'; // Define your symbol explicitly
$decimalPlaces = 2;
$width = 10;

$pricetotal = number_format($pricetotal, $decimalPlaces, '.', ' ');

The primary advantage of number_format() over the removed money_format() is the ability to define the decimal separator and the thousands separator explicitly. By passing the decimal point character (e.g., '.') and the thousands separator (e.g., ' ' for a space or ',' for a comma) as arguments, you ensure that your prices render identically regardless of whether the server is running on Linux, Windows, or macOS.

In your specific case, where you are building a PayPal cart integration, consistency is paramount. If the price displayed to the user differs from the amount sent to PayPal due to locale mismatches, it creates a trust issue and potential payment failures. Using number_format() allows you to hardcode the formatting to match your desired output (e.g., $123.45) without depending on setlocale(). While setlocale(LC_MONETARY, "en_US") is used in your script, relying on it for currency formatting is fragile because changing server locales can break this logic entirely.

Additionally, your code snippet contains several other critical security and stability issues that should be addressed alongside this function deprecation:

  1. Deprecated MySQL Extension: You are using mysql_query() and mysql_fetch_array(). These functions were removed in PHP 7.0. You must migrate to mysqli or PDO with prepared statements. Passing variables directly into the query string (e.g., "SELECT * FROM products WHERE id='$item_id'") exposes your application to SQL injection attacks.
  2. PayPal API Changes: The code constructs a PayPal Classic cart URL manually (cmd=_cart). Modern implementations should generally use the PayPal Buttons SDK or REST APIs, which handle currency formatting and transaction details securely on their end.

If you are maintaining this legacy codebase and cannot immediately rewrite the entire PHP core logic, consider installing an older version of PHP (like 5.6) alongside your modern version using a containerized environment or a multi-version manager like php-build. However, this is a temporary workaround that sacrifices security patches and performance. The recommended path is to update the codebase to use number_format() and migrate the database layer to MySQLi or PDO immediately.

For developers looking for enterprise-grade solutions that handle currency logic, localization, and secure payment integrations out of the box, you might explore specialized packages. While standard libraries like Laravel provide robust financial utilities, legacy PHP scripts often lack these abstractions. If your project eventually migrates to a modern framework like Laravel, you will find native support for currency formatting via the money package or similar ecosystem tools that abstract away the complexities of locale handling entirely.

Our network