â ī¸ Warning â ī¸ Deprecated Code! This video tutorial contains outdated code.
đĄ If you wish to update it, any AI assistant will update the code for you in seconds.
đĄ If you wish to update it, any AI assistant will update the code for you in seconds.
Using the method_exists Function
The method_exists() function will evaluate to see if the specified method exists. It returns TRUE if the method is found and FALSE if it is not.
demo.php
<?php
include_once("class1.php");
$myObj = new class1();
if(method_exists($myObj, "sayhello")){
echo $myObj->sayhello();
} else {
echo "sayhello method does not exist";
}
?>
class1.php
<?php
class class1 {
public function sayhello(){
return "Hello";
}
}
?>