Page 204 - Open Soource Technologies 304.indd
P. 204

Web Technologies-I



                   Notes            •  PHP gives us a very simple way to define an object programmatically, and this is called
                                      a class.
                                    •  A class is a wrapper that defines and encapsulates the object along with all of its methods
                                      and properties.

                                    •  A method is essentially a function within a class, and a class may contain no methods, or
                                      thousands of methods. Properties are exactly what they seem to be, they are the properties
                                      of the object, and we usually use methods to set, modify and get properties from an object.
                                    •  The data associated with an object are called its properties. The functions associated with
                                      an object are called its  methods.  When  you  define  a  class,  you  define  the  names  of  its
                                      properties and give the code for its methods.

                                    •  PHP is not an object-oriented language, it has extensive support for objects. Also, since
                                      PHP 5, many core aspects of the language use objects rather than ordinary (procedural)
                                      functions.
                                    •  Classes can be considered as a collection of methods, variables and constants. They often
                                      reflect a real-world thing, like an animal class or a bird class.
                                    •  Visibility is a big part of OOP. It allows you to control where your class members can be
                                      accessed from, for instance to prevent a certain variable to be modified from outside the
                                      class.

                                    •  Abstract classes are special because they can never be instantiated. Instead, you typically
                                      inherit a set of base functionality from them in a new class.  For that reason, they are
                                      commonly used as the base classes in a larger class hierarchy.
                                    •  Object introspection is an often overlooked feature in PHP. With the advent of PHP 5
                                      there are all sorts of new additions to the world of PHP object introspection as well.

                                    •  Abstract  classes  are  similar  in  many  ways  to  interfaces.  The  main  difference  between
                                      an abstract and an interface is that abstracts allow some control over how the declared
                                      methods are defined.

                                 8.9 Keywords

                                 Abstract class: Abstract class  is  a class  that can not be instantiated, it exists extensively for
                                 inheritance and it must be inherited. There are scenarios in which it is useful to define classes
                                 that are not intended to instantiate; because such classes normally are used as base-classes in
                                 inheritance hierarchies, we call such classes abstract classes.

                                 Class: A class is a template definition of the methods and variables in a particular kind of object.
                                 Constant: A constant is, just like the name implies, a variable that can never be changed.
                                 Constructor: Constructor is a default member function available with a class. It can be explicitly
                                 defined in a class to initialize the variables. Constructor is called when an object is created for
                                 a class.

                                 Destructor:  Destructor  is  special  functions  which  are automatically  called  when an object  is
                                 created and destroyed.

                                 Inheritance: Inheritance is one of the most important aspects of OOP. It allows a class to inherit
                                 members from another class.
                                 Introspection: Object introspection refers to the ability of a class object to reveal information
                                 about itself, such as methods and variables.



        198                               LOVELY PROFESSIONAL UNIVERSITY
   199   200   201   202   203   204   205   206   207   208   209