Skip to Content
Mastering PHP 7
book

Mastering PHP 7

by Branko Ajzele
June 2017
Intermediate to advanced
536 pages
9h 49m
English
Packt Publishing
Content preview from Mastering PHP 7

Using __set()

Aside from method overloading, property overloading is another aspect of the PHP overloading capabilities. There are four magic methods in PHP that support the property overloading: __set(), __get(), __isset(), and __unset(). Throughout this section, we will take a closer look at the __set() method.

The __set() magic method is triggered when trying to write data to inaccessible properties. 

The method accepts two parameters, as per the following synopsis:

public void __set(string $name, mixed $value)

Whereas, the __set() method parameters have the following meaning:

  • $name: This is the name of the property being interacted with
  • $value: This is the value that the $name property should be set to

Let's take a look at the following ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning PHP 7

Learning PHP 7

Antonio L Zapata (GBP)
Upgrading to PHP 5

Upgrading to PHP 5

Adam Trachtenberg

Publisher Resources

ISBN: 9781785882814Supplemental Content