Changes

Jump to: navigation, search

PHP Object Oriented Programming

246 bytes added, 19:06, 6 June 2007
Class Constructor and Destructor
We have now defined a class. The next step is add some functionality to the class.
== PHP Class Constructor Constructors and Destructor Destructors ==
The next step in creating a class is to define what should happen when an object is first instantiated using the class, and also when that object is later destroyed. These actions are defined the ''constructor'' and ''destructor'' methods of the class.
The constructor and destructor are really just functions that get called when the object is created and destroyed and are defined in the class body using the ''function'' keyword. This needs to be prefixed witwith the ''public'' qualifier. This means the method is accessible to code outside of the object. The default names fo rthe constructor and destructor are __construct and __destruct respectively. We can now expend out bankAccount class: <pre>

Navigation menu