Page 330 - Computer Software Application TP - Volume 1
P. 330

COMPUTER SOFTWARE APPLICATION - CITS



           EXERCISE 60 : Perform class constants, Class inheritance,

                                     Abstract classes and  methods,  Object

                                     serialization,  checking  for  class and

                                     method, existence, Exceptions, Iterators

            Objectives

           At the end of this exercise you shall be able to
           •  use inheritance and abstract classes in PHP
           •  use object serialization in PHP
           •  use exceptions and lterators in PHP.

           Requirements

           Tools/Materials
           •   Computer/Laptop with latest configuration       •  PHP
           •   Operating system: windows 10 or 11              •  Text editor
           •  Apache web server                                •  Web browser

           Procedure


           TASK 1: Using class constants
           1  Open the text editor

           2  Write the following codes
              <html >
                 <head>
                       <title> class constants </title>

                 </head>
                 <body>
                        <?php
                              class MathConstants
                       {
                              const PI = 3.14159;

                              const E = 2.71828;
                              public function printConstants()
                              {
                                            echo “The value of PI is: “ . self::PI . “<br/>”;

                                            echo “The value of E is:  “ . self::E . “<br/>”;
                              }
                       }
                       class Circle
                       {





                                                           315
   325   326   327   328   329   330   331   332   333   334   335