Page 329 - Computer Software Application TP - Volume 1
P. 329
COMPUTER SOFTWARE APPLICATION - CITS
<body>
<?php
class MyClass
{
// Destructor
public function __destruct()
{
echo “Destructor called\n”;
}
}
// Creating an object of MyClass
$obj = new MyClass();
// The object will be destroyed at the end of the script
?>
</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.
1 Create an object of a class named Car in PHP, which has properties such as $make, $model, and $year. Assign
values to these properties during object instantiation.
2 Create a PHP class called Book with properties $title, $author, and $price. Write a constructor method to initialize
these properties. Instantiate an object of the Book class with the title “PHP Programming”, author “John Doe”, and
price $29.99.
3 Create a PHP class Employee with private properties $name and $salary. Implement getter and setter methods
for these properties. Instantiate an Employee object and set the name to “John” and salary to 50000.
314
CITS : IT & ITES - Computer Software Application - Exercise 59