SlideShare a Scribd company logo
welcome
What is magic Method?
Special methods which are called implicitly as an internal steps of the PHP code
executions. All the magic methods name start with __(double underscore)
List of the magic methods
● __get($property)
● __set($property, $value)
● __call($fun, $arg)
● __callStatic($fun, $arg)
● __construct()
● __destruct()
● __isset($content)
● __unset($content)
● __serialize()
● __unserialize()
● __sleep()
● __wakeup()
● __toString()
● __invoke()
● __set_state($array)
● __clone()
● __debugInfo()
__get($property)
<?php
class Foo
{
public $info = "this is info prop n";
public function __get($property)
{
echo "$property is not exist";
}
}
echo (new Foo)->info; # this is info prop
(new Foo)->random_property; # random_property is not exist
__set($property, $value)
?php
class Foo
{
public $info = "this is info prop n";
public function __set($property, $value)
{
echo "$property is not exist";
}
}
$obj = new Foo
$obj->info = “new value”;
echo $obj->info; // new value
$obj->bar = “this is bar”; // bar is not exist
In Laravel where are these being used? (__get($property)
& __set($property, $value))
- Laravel stores all the DB columns in protected $attributes associative array
- When we try to access any value from db, since that property does exist on the
model, php called the __get method with the property name
- With in __get method, laravel check passing property in the associative array
and return the corresponding value
class User
{
protected $attributes = [ ];
public function __get(string $key)
{
if(!array_key_exists($key, $attributes)) {
return null;
}
return $this->attributes[$key];
}
public function __set($key, $val)
{
$this->attributes[$key] = $val;
}
}
$user = new User;
$user->firstName; // null
$user->firstName = 'Alice'; // $attributes = [ 'firstName' => 'Alice']
$use->lastName = “foo”; // $attributes = [ 'firstName' => 'Alice', “lastName” => “foo” ]
property_exists( $user , ‘firstName’ ); // will return false
__call($name, $arguments)
__call is executed when a method was called but not found in a specific class
Example:
<?php
class Foo
{
public function __call($method, $arg)
{
echo "$method was called with argument $arg[0] but that method does not exist";
}
}
(new Foo)->randomMethod('test');
# randomMethod was called with argument test but that method does not exist
__callStatic($name, $arg)
<?php
class Foo
{
public static function __callStatic($name, $arg) {
echo "Static method $name is called that does not exist";
}
}
Foo::random(); # Static method random is called that does not exist
How __call($name, $arguments) and __callStatic($name, $arg)
are being used in the Laravel?
Short answer: to provide feature like macro and facade, laravel use __call() &
__callStatic()
What is macro: Using macro we can add additional functionality to the Laravel
internal component like: Request, Response, Collection class
Example of macro
Let’s say you are working with the api and want the below response on success.
{
"success": true,
"msg": "Your message",
"data": Array()
}
We can create this format from the controller and send as response but that is not
good solution as this is not reusable and we have to refactor every controllers if
we want to change the format in future
How can we create re-usable format? One way could be macro
We can create an macro and bind to any service Providers root method (ex.
AppServiceProvider)
public function boot()
2
{
3
Response::macro(‘success’, function ($msg, $data) {
return response()->json([
"success" => true,
"msg" => $msg,
"data" => $data
]);
});
7
}
// calling the macro.
Response::success(“message”, []); // call as static method
$response->success(“message”, []); // call as instance method
How __call($name, $arguments) and __callStatic($name,
$arg) are used to create macro?
Link to the laravel macroable trait:
https://github.com/laravel/framework/blob/e6c8aa0e39d8f91068ad1c299546536e9
f25ef63/src/Illuminate/Support/Traits/Macroable.php
When should we use these magic method?
- usually not anywhere during normal application development
- we might need during implementation of the Library
References
https://www.php.net/manual/en/language.oop5.magic.php
https://liamhammett.com/laravel-mixins-KEzjmLrx
https://dev.to/nvio/laravel-greatest-trick-revealed-magic-methods-31om
https://www.php.net/manual/en/function.call-user-func-array.php
https://www.php.net/manual/en/closure.bindto.php
END

More Related Content

Similar to Magic function in PHP

SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
jsmith92
 
SPL, not a bridge too far
SPL, not a bridge too farSPL, not a bridge too far
SPL, not a bridge too far
Michelangelo van Dam
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
James Titcumb
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
Thomas Weinert
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
Marcello Duarte
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
Chhom Karath
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
Damien Seguy
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016
Britta Alex
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards
Denis Ristic
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
brian d foy
 
Building a horizontally scalable API in php
Building a horizontally scalable API in phpBuilding a horizontally scalable API in php
Building a horizontally scalable API in php
Wade Womersley
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
Hugo Hamon
 
Intro to The PHP SPL
Intro to The PHP SPLIntro to The PHP SPL
Intro to The PHP SPL
Chris Tankersley
 
Magic methods
Magic methodsMagic methods
Magic methods
Matthew Barlocker
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
Bradley Holt
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
Jagat Kothari
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Dhivyaa C.R
 
UNIT IV (4).pptx
UNIT IV (4).pptxUNIT IV (4).pptx
UNIT IV (4).pptx
DrDhivyaaCRAssistant
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
Stephan Schmidt
 

Similar to Magic function in PHP (20)

SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
SPL, not a bridge too far
SPL, not a bridge too farSPL, not a bridge too far
SPL, not a bridge too far
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
 
Building a horizontally scalable API in php
Building a horizontally scalable API in phpBuilding a horizontally scalable API in php
Building a horizontally scalable API in php
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
 
Intro to The PHP SPL
Intro to The PHP SPLIntro to The PHP SPL
Intro to The PHP SPL
 
Magic methods
Magic methodsMagic methods
Magic methods
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
 
UNIT IV (4).pptx
UNIT IV (4).pptxUNIT IV (4).pptx
UNIT IV (4).pptx
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 

Recently uploaded

Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
Massimo Artizzu
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
NishanthaBulumulla1
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 

Recently uploaded (20)

Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 

Magic function in PHP

  • 2. What is magic Method? Special methods which are called implicitly as an internal steps of the PHP code executions. All the magic methods name start with __(double underscore)
  • 3. List of the magic methods ● __get($property) ● __set($property, $value) ● __call($fun, $arg) ● __callStatic($fun, $arg) ● __construct() ● __destruct() ● __isset($content) ● __unset($content) ● __serialize() ● __unserialize() ● __sleep() ● __wakeup() ● __toString() ● __invoke() ● __set_state($array) ● __clone() ● __debugInfo()
  • 4. __get($property) <?php class Foo { public $info = "this is info prop n"; public function __get($property) { echo "$property is not exist"; } } echo (new Foo)->info; # this is info prop (new Foo)->random_property; # random_property is not exist
  • 5. __set($property, $value) ?php class Foo { public $info = "this is info prop n"; public function __set($property, $value) { echo "$property is not exist"; } } $obj = new Foo $obj->info = “new value”; echo $obj->info; // new value $obj->bar = “this is bar”; // bar is not exist
  • 6. In Laravel where are these being used? (__get($property) & __set($property, $value)) - Laravel stores all the DB columns in protected $attributes associative array - When we try to access any value from db, since that property does exist on the model, php called the __get method with the property name - With in __get method, laravel check passing property in the associative array and return the corresponding value
  • 7. class User { protected $attributes = [ ]; public function __get(string $key) { if(!array_key_exists($key, $attributes)) { return null; } return $this->attributes[$key]; } public function __set($key, $val) { $this->attributes[$key] = $val; } } $user = new User; $user->firstName; // null $user->firstName = 'Alice'; // $attributes = [ 'firstName' => 'Alice'] $use->lastName = “foo”; // $attributes = [ 'firstName' => 'Alice', “lastName” => “foo” ] property_exists( $user , ‘firstName’ ); // will return false
  • 8. __call($name, $arguments) __call is executed when a method was called but not found in a specific class Example: <?php class Foo { public function __call($method, $arg) { echo "$method was called with argument $arg[0] but that method does not exist"; } } (new Foo)->randomMethod('test'); # randomMethod was called with argument test but that method does not exist
  • 9. __callStatic($name, $arg) <?php class Foo { public static function __callStatic($name, $arg) { echo "Static method $name is called that does not exist"; } } Foo::random(); # Static method random is called that does not exist
  • 10. How __call($name, $arguments) and __callStatic($name, $arg) are being used in the Laravel? Short answer: to provide feature like macro and facade, laravel use __call() & __callStatic() What is macro: Using macro we can add additional functionality to the Laravel internal component like: Request, Response, Collection class
  • 11. Example of macro Let’s say you are working with the api and want the below response on success. { "success": true, "msg": "Your message", "data": Array() } We can create this format from the controller and send as response but that is not good solution as this is not reusable and we have to refactor every controllers if we want to change the format in future How can we create re-usable format? One way could be macro
  • 12. We can create an macro and bind to any service Providers root method (ex. AppServiceProvider) public function boot() 2 { 3 Response::macro(‘success’, function ($msg, $data) { return response()->json([ "success" => true, "msg" => $msg, "data" => $data ]); }); 7 } // calling the macro. Response::success(“message”, []); // call as static method $response->success(“message”, []); // call as instance method
  • 13. How __call($name, $arguments) and __callStatic($name, $arg) are used to create macro? Link to the laravel macroable trait: https://github.com/laravel/framework/blob/e6c8aa0e39d8f91068ad1c299546536e9 f25ef63/src/Illuminate/Support/Traits/Macroable.php
  • 14. When should we use these magic method? - usually not anywhere during normal application development - we might need during implementation of the Library
  • 16. END