Constructors and Destructors in php


When creating a new object, you can pass a list of arguments to the class being called. These are passed to a special method within the class, called the constructor, which initializes various properties.
In the past, you would normally give this method the same name as the class, as in following Example.

class BaseClass
function __construct() {
       echo "Called by default";
   $obj = new BaseClass();


Also new in PHP 5 is the ability to create destructor methods. This ability is useful when code has made the last reference to an object or when a script reaches the end

class User		
	function __destruct()	
		// Destructor code goes here

You may also like...

No © Loop and Break