Objects

My favorite comparisons are mobile telephones (called cell phones in some countries) in a car. Car manufacturers design cars with a standard size hole in the dashboard for a radio or CD player but not for a mobile phone. If you want great reception, hands free operation and no annoying cables everywhere, you have to buy a car kit to suit your phone, get the car kit fitted then throw the whole kit away when you upgrade to a new phone. The equivalents in software are objects.

A PHP object can be used in any PHP script in the world, but every calendar object has a different interface, so you cannot just unplug one calendar object and plug in another. A class is a prototype for an object and contains all the code to assemble object, so objects of the same class have the same interface while objects of different classes have a different interface even if designed to perform the same function. An object's interface is the collection of properties and methods within the object. The assembly of an object from a class is performed using the keyword new and a special function in the class named a constructor.

Chapter 17 Objects contains the following sections.

   In Depth
      Classes
         new
         Like a Variable
         stdClass
         __
      Properties
         var
         Constructor
         $this
      Methods
         Destructor
      Extending Classes
         Adding Functions
         Constructors in Extended Classes
         Replacing Functions
         Deleting Functions
         Multiple Extensions
         ::
         parent
      Software Distribution and Documentation
         Multiple Data Items and State
         Multiple Outputs

   Immediate Solutions
      Saving Objects in Sessions and Using __sleep()
      Using Object Functions
         call_user_method()
         call_user_method_array()
         class_exists()
         get_class()
         get_class_methods()
         get_class_vars()
         get_declared_classes()
         get_object_vars()
         get_parent_class()
         is_subclass_of()
         method_exists()
      Customising Your Web Page with an Object
      Reading the News