From d7736fb8be85f7080ca4246e2b642173c23820d5 Mon Sep 17 00:00:00 2001 From: Daniele Pedone Date: Thu, 28 Mar 2019 23:33:08 +0100 Subject: [PATCH] Added Magic Methods (#31344) * Added Magic Methods * Update index.md --- .../php/object-oriented-programming/index.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/guide/english/php/object-oriented-programming/index.md b/guide/english/php/object-oriented-programming/index.md index e9463d34576..b2d047a6ad4 100644 --- a/guide/english/php/object-oriented-programming/index.md +++ b/guide/english/php/object-oriented-programming/index.md @@ -371,3 +371,25 @@ echo json_encode($jack->getFavDrinks()); ``` This way of implementing and using class methods to retrieve and update class properties is called encapsulation in Object Oriented Programming. We can also set visibility for class methods just like how we did it for class properties. + +### MAGIC METHODS + +There are some special methods that Php uses for its own purpose. + +Suppose you want to threat an object as a string. You can do that by overriding `__toString()` method into related class: + +``` +