{"id":2815,"date":"2024-12-31T20:26:43","date_gmt":"2024-12-31T20:26:43","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/solution-call-to-undefined-function-bccomp-in-magento-2\/"},"modified":"2025-01-02T10:00:26","modified_gmt":"2025-01-02T10:00:26","slug":"call-to-undefined-function-bccomp-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/call-to-undefined-function-bccomp-in-magento-2\/","title":{"rendered":"Solution: Call to Undefined Function bccomp() in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Are you facing the&nbsp;<em><strong>call to undefined function bccomp() in Magento 2<\/strong><\/em>? Recently, I faced the same error while working on a client\u2019s site.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here, I am sharing the solution that worked for me.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/business.adobe.com\/products\/magento\/magento-commerce.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento<\/a>&nbsp;is an open-source e-commerce platform written in Php language. It requires a supported version of Php along with several libraries to function properly. One such required Php extension is the BCMath.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Magento uses various functions of&nbsp;<a href=\"https:\/\/www.php.net\/manual\/en\/book.bc.php\" target=\"_blank\" rel=\"noreferrer noopener\">BCMath Php extension<\/a>&nbsp;at various steps.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, the bccomp() function compares the values of two long numbers during add-to-cart. In case the BCMath extension is missing, all those features may get affected.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the present case, the customer was not able to add a product to the cart. On checking the&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/how-to-enable-error-logs-in-magento-2\/\">error log of Magento 2<\/a>&nbsp;I found the following:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Call to undefined function MagentoInventorySalesModelIsProductSalableForRequestedQtyConditionbccomp()<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel relaxed! I got a 100% working solution to this.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Fix Call to Undefined Function bccomp() in Magento 2?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The error clearly interprets that Magento 2 is not able to find the bccomp() function. This can be because the BCMath extension is either disabled or not installed in Php.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The BCMath extension may go missing because of multiple reasons, such as after the Php version upgrade or the&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/how-to-upgrade-magento-2-to-latest-version\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento version upgrade<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The solution is simple: Enable the Php BCMath extension in the setup!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">For Local Server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you\u2019re facing the Call to Undefined Function bccomp() in Magento 2 local installation, follow these steps to enable the BCMath Php extension:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the XAMPP Control Panel, and go to\u00a0<strong>Configure > PHP<\/strong>\u00a0in the Apache module.<\/li>\n\n\n\n<li>In the Php.ini file, search for\u00a0<code>extension=php_bcmath.dll<\/code>, remove\u00a0<code>;<\/code>\u00a0before it and save the file.<\/li>\n\n\n\n<li>Restart the server.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">For Live Server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You\u2019ll need to contact the respective hosting provider to enable the BCMath Php extension in your setup. If you\u2019re a root user, you can also use the following command to do that:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install php7.2-bcmath<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Remember to tweak the Php version in the above command as per the configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&amp; that\u2019s it\u2026<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enabling the BCMath Php extension in will solve the Call to Undefined Function bccomp() in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The add-to-cart function on the front end will start working normally again.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you think this solution has helped you, rate it five stars and share it on social media\u2026.!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to comment down your thoughts..  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you facing the&nbsp;call to undefined function bccomp() in Magento 2? Recently, I faced the same error while working on a client\u2019s site. Here, I&#8230;<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-2815","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=2815"}],"version-history":[{"count":1,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2815\/revisions"}],"predecessor-version":[{"id":3768,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2815\/revisions\/3768"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}