Checking if a function already exists

Declaring the same function twice will trigger an error message and stop the script.
If there is an include with a function but it’s not pulled on all pages and you wish to add the function when the file wasn’t included use:

<?php
if (function_exists(‘function_name’)) {
echo 
“It’s loaded!”;
} else {
include($_SERVER[‘DOCUMENT_ROOT’].’/function.php’);
}
?>

Leave a Reply

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