Tuesday, November 20, 2007

OOPs Possible in PHP

Now, in the computer programming world, object-oriented programming (OOP) has rapidly taken hold as the programming methodology of choice for the enterprise. The basic concept is encapsulation - the grouping of data and code elements that shar common traits inside a container known as class.


A class contains the definition of data elements (or properties) and functions (or methods) that share some commont trait and can be encapsulated in a single structure. A class is declared using the class structure:



  • // class keyword is followed by name of class: vehicle
  • class vehicle
  • {
  • // Data property
  • var $type;

  • // a method, if same name as the class, it as the class constructor. Automatically called whenever class is instantiated
  • // have paramater $type
  • function vehicle( $type )
  • {
  • $this->type = $type;
  • }

  • }

  • ?>
  • 1 comment:

    Sabarinathan Iyer said...

    Simple example for Beginning Object Oriented Programming in PHP