DESTRUCTOR

  • PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++.
  • The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed in any order in shutdown sequence.
  • We create destructor by using "__destruct" function.

Example 1

snippet
<?php
	class demo
	{
		public function demo()
		{
			echo "constructor1...";
		}
	}
	
	class demo1 extends demo
	{
		public function __construct()
		{
			echo parent::demo();
			echo "constructor2...";
		}
		public function __destruct()
		{
			echo "destroy.....";
		}
	}
	$obj= new demo1();
?>

Output:

DESTRUCTOR
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents