How to check if function exists?

Posted by nikola, With 0 Comments, Category: PHP, Tags:

Or - how to avoid re-declaring functions?

Function redeclaration often occurs if you work with different versions of PHP, ie. on development and on production server.

In that case we usually use PHP function function_exists. In next example we will check if function money_format is defined or not.

if (!function_exists('money_format')) {
  function money_format() {
  // here you can write your custom function
  return 0;

Just to know, function money_format() is only defined if the system has strfmon capabilities, so it is not available on Windows versions of PHP.