Delete an object using unset() function in PHP
Orignal Source:http://codingvilla.com/delete-object-unset-function-php-single-article-574.aspx
Object:
An object is anything that has state and behavior. An object is an instance of a class.
Example:
Dog
State: name, color, breed
Behavior: sitting, barking, waging tail, running
Objects in PHP:
The concept of objects in php is same as in other programming languages. Objects in php are created with new keyword to instantiate a class.
Code:
<?php
class foo
{
function do_foo()
{
echo "Doing foo.";
}
}
$bar = new foo; //create object of class foo
$bar->do_foo();
?>
Delete Objects in PHP:
To delete an object in php we use unset () function that take object as a parameter and delete that object. The unset () function is built in function in php.
Code:
<?php
function destroy_foo()
{
global $foo;
unset($foo);
}
$foo = 'bar';
destroy_foo();
echo $foo;
?>
Above is a simple code to delete an object using unset () function in php.
This simple article tells that how we can delete an object using unset () function in php.
Tags: delete, object, using, unset, function, php
Comments
