PHP Basics

Setter

Writes data to inaccessible properties by using magic methods.

To make a protected or private property writable, provide a method named _magicSet{Property}() which handles the writing. Replace {Property} in the method's name with the name of the actual property (with an uppercase first letter).

Example: If the property is named $fooBar, the "magic" method has to be _magicSetFooBar(). This method is then called when $fooBar is written to in a context where it normally would not be accessible.

Tags
author

Sebastian Meyer sebastian.meyer@opencultureconsulting.com

Table of Contents

Methods

__set()  : void
Write data to an inaccessible property.
__unset()  : void
Unset an inaccessible property.

Methods

__set()

Write data to an inaccessible property.

public __set(string $property, mixed $value) : void
Parameters
$property : string

The class property to set

$value : mixed

The new value of the property

Tags
throws
InvalidArgumentException

if the property or setter method do not exist

__unset()

Unset an inaccessible property.

public __unset(string $property) : void
Parameters
$property : string

The class property to unset


        
On this page

Search results