php code to check if function exists or not

when we are doing coding a project,their is a chance of misspelling the function name it will end up with an error function does not exists error php,so before calling a function you have to check if the function is already define or not,for we have simple php code to check if function exists or not here is the syntax

function_exists(FUNCTION_NAME_HERE);

This will Return true if the function is defined

e.g

if(function_exists('new_func')){
  //new_func is defined

  new_func();  call that function  
}

This function we can use at the time of defining a function,otherwise you will get an error message saying already the function “new_func” is defined

So for before all fucntion declare case you have to use function_exists(‘new_func’) fucntion to double confirm no where the function is define more than one times

see the error message here

php-code-to-check-if-function-exists-or-not

if(!function_exists('new_func')){
 function new_func()
 {
  echo "php code to check if function exists or not";	 
 }
}

Out put
php code to check if function exists or not

My Thought

Your email address will not be published. Required fields are marked *

Our Tool : hike percentage calculator