Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PHP, how do I check if a function exists?

Tags:

function

php

How can I check if the function my_function already exists in PHP?

like image 649
bradg Avatar asked Dec 04 '10 03:12

bradg


People also ask

How do we know if a function exists?

Use an if Conditional Statement The code in the brackets will execute if the function is defined. If instead you just test the function without using the window object, for example as if(aFunctionName) , JavaScript will throw a ReferenceErorr if the function doesn't exist.

How do you check if a class has a method PHP?

Use the PHP method_exists() function to check if an object or a class has a specified method.

Which is the not a function of in PHP?

2. Which of the following is not a built-in function in php ? Explanation: fclosed() is not a built-in function in php.

Is callable in PHP?

The is_callable() function checks whether the contents of a variable can be called as a function or not. This function returns true (1) if the variable is callable, otherwise it returns false/nothing.


2 Answers

Using function_exists:

if(function_exists('my_function')){     // my_function is defined } 
like image 80
Mark Elliot Avatar answered Sep 21 '22 20:09

Mark Elliot


http://php.net/manual/en/function.function-exists.php

<?php   if (!function_exists('myfunction')) {       function myfunction()      {        //write function statements      }  }  ?> 
like image 35
Avinash Saini Avatar answered Sep 21 '22 20:09

Avinash Saini