From 64aa38a1d28d6e3b9f770e97476f0111f180bd3e Mon Sep 17 00:00:00 2001 From: Akshay Kalose Date: Fri, 16 Oct 2015 22:07:08 -0400 Subject: [PATCH 1/2] Add More Magic Methods in PHP --- php.html.markdown | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/php.html.markdown b/php.html.markdown index 39ec5aef..78d9d1f2 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -498,10 +498,23 @@ class MyClass print 'MyClass'; } - //final keyword would make a function unoverridable + // final keyword would make a function unoverridable final function youCannotOverrideMe() { } + + // Magic Methods + + // what to do if Object is treated as a String + public function __toString() { + return $property; + } + + // opposite to __construct() + // called when object no longer referenced + public function __destruct() { + print "Destroying" + } /* * Declaring class properties or methods as static makes them accessible without From d9f3b13e278eebb173253c756ffe847b3188f4af Mon Sep 17 00:00:00 2001 From: Akshay Kalose Date: Sun, 18 Oct 2015 17:37:39 -0400 Subject: [PATCH 2/2] Fix Grammar and Syntax --- php.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php.html.markdown b/php.html.markdown index 78d9d1f2..ac0a83b9 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -511,9 +511,9 @@ class MyClass } // opposite to __construct() - // called when object no longer referenced + // called when object is no longer referenced public function __destruct() { - print "Destroying" + print "Destroying"; } /*