DEV Community

Cover image for PHP: Getters and Setters
professional writer
professional writer

Posted on

PHP: Getters and Setters

In this guide, we are going to show you how to create “Getters” and “Setters” using PHP.

“Getters” and “Setters” are class functions that allow you to control access to an object’s properties.

Sometimes, people will refer to them as “mutator methods”.

To sum it up:

A “getter” allows you to retrieve or get a given property.

A “setter” allows you to set the value of a given property.

read more

Top comments (1)

Collapse
 
sloan profile image
Sloan the DEV Moderator

Hi there, we encourage authors to share their entire posts here on DEV, rather than mostly pointing to an external link. Doing so helps ensure that readers don’t have to jump around to too many different pages, and it helps focus the conversation right here in the comments section.

If you choose to do so, you also have the option to add a canonical URL directly to your post.