3. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
4. What is a MAGIC METHOD ??
•A special method ,starting with __.
• Methods which will be triggered in response to
particular PHP events.
5. Some Examples for Magic Methods
__construct()
__destruct()
__get()
__set()
__isset()
__unset()
6. __construct
A method that gets called when the object is instantiated
Eg :
<?php
class Books
{
public function __construct()
{
echo "Using the magic method...<br />";
}
}
$physics = new Books;
?>
7. __destruct
It gets run when all the reference to an object is removed.
Object is explicitly destroyed.
This method is called even if the script exits due to a call to exit()
EG ::
<?php
class Books
{
function __destruct()
{
echo "This object is no longer needed..";
}
}
$a=new Books();
unset($a);
?>
8. __get
•This method called when your object attempt to read property or variable
of the class which is inaccessible or unavailable.
__set
•When object of your class attempts to set value of the property which is
really inaccessible or unavailable in your class.
__isset
•It will trigger when isset() function is applied on any property of the class
which is inaccessible or unavailable.
__unset
•It is something opposite of isset method.
•This method called when unset() function called on inaccessible
•or unavailable property of the class.
10. Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
11. Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
12. Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us
Editor's Notes
__get &__set -- directly related with no accessible method and property of the class.