Page 335 - Computer Software Application TP - Volume 1
P. 335
COMPUTER SOFTWARE APPLICATION - CITS
TASK 4: Checking for class and method existence
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Checking for class and method existence </title>
</head>
<body>
<?php
// Define a class
class MyClass
{
public function myMethod()
{
echo “Hello from myMethod!<br/>”;
}
}
// Check if class exists
if (class_exists(‘MyClass’))
{
echo “MyClass exists. <br/>”;
}
else
{
echo “MyClass does not exist. <br/>”;
}
// Check if method exists in the class
if (method_exists(‘MyClass’, ‘myMethod’))
{
echo “myMethod exists in MyClass. <br/>”;
}
else
320
CITS : IT & ITES - Computer Software Application - Exercise 60