PHP tutorials
Question:
How can I check to see if a function, method or class exists before I call it?
Answer:
Use the function_exists function. This is useful if the function you're using is only available from a later version of php or part of an extension package that may not have been included in the php install.
<?php
array $newArray;
if(function_exists(array_splice))
{
$newArray = array_splice($myArray, 5);
}
else
{
//need to find another way to do array_splice...
}
?>
Additional Notes
Also check out method_exists and class_exists
PHP Reference Manual
array_splice - Chops up an array...
class_exists - Determine if a class exists
function_exists - Determines if a function exists
method_exists - Determines if a method exists
Comments or questions relating to this article have been disabled. They will be back soon.
Copyright
Let notice be given that this is copyright information