Page 337 - Computer Software Application TP - Volume 1
P. 337
COMPUTER SOFTWARE APPLICATION - CITS
// Serialize the object
$serializedObj = serialize($obj);
// Output the serialized object
echo “Serialized object: $serializedObj<br/>”;
// Unserialize the object
$unserializedObj = unserialize($serializedObj);
// Output the unserialized object
echo “Unserialized object:\n”;
var_dump($unserializedObj);
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
TASK 6: Using Exceptions
I Using try, catch, and throw keywords
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Exceptions </title>
</head>
<body>
<?php
function divide($dividend, $divisor)
{
if ($divisor === 0)
{
throw new MyCustomException(“Cannot divide by zero!”);
322
CITS : IT & ITES - Computer Software Application - Exercise 60