Changes

PHP Object Oriented Programming

7 bytes added, 20:16, 7 June 2007
no edit summary
PHP provides extensive support for developing object-oriented web applications. The area of object oriented programming is, however, large. Entire books can, and indeed have, been dedicated to the subject. As such, a detailed overview of object oriented software development is beyond the scope of this [[PHP bookEssentials]]. Instead we will introduce the basic concepts involved in object oriented programming and then move on to explaining the concept as it relates to PHP development.
== What is an Object? ==
== How is an Object Created from a Class? ==
The process of creating an object from the class 'blueprint' is called instantiation. Essentially, you instantiate an instance of the class and give that instance a name by which you will refer to it when acessing accessing members and calling methods. You can create as many object instances of a class as you desire. Objects are instantiated using the ''new'' keyword. For example, to create an instance of a class called ''bankAccount'' we would write:
<tt>$accountObject = new bankAccount();</tt><br>
== PHP Object Serialization ==
One of the interesting feature features of object oriented programming is the ability to take a snapshot of the current state of an object and then save that object to a file, or even transmit it over a network to another process where it will be re-activated. This concept is known in the object oriented world as ''object serialization''.
All objects have built-in method called ''__sleep'' that is called before serialization. If you need your object to perform any housekeeping before being serialized you will need to override this method.