GetSetGo-Php Dynamic Setter Getter Library

GetSetGo is a dynamic setter-getter library for PHP 5.4+. Its developed by me and Muhammed Usman, and yes, it’s well unit tested.

You can use methods like setFoo('bar') and getFoo(), which you don’t have to create (in your class). GetSetGo will make these methods work for you automatically as long as you have a $foo property in your class.

It makes use of Traits, so using it is super simple, you don’t have to extend any class, as you can extend a single class only, we don’t force you to use ours. You can restrict to only getter or setter or you can specify a Type for property using annotations.

View on GitHubPackagist


GetSetGo uses Composer to make it easy to use. If you don’t know how to use composer then learn it and add the following line in your composer.json file in the require section :


Just add use \GetSetGo\SetterGetter in your classes to make it available in the classes where you want to use it, for example :

Now you can use it as follows :

This is the basic use of this.

Restrict Getter or Setter or Both

You can use annotation in you class property if you want to disable setter, getter or both.
For a readOnly property you can restrict the Setter

Set the Getter restricted

Restrict both if you want

Type Casting

It has to be an array in the given example

It has to be an String in the given example

It has to be a Number in the given example

You can also use

GetSetGo assumes that you use proper camelCase so name your properties like $pdoInstance not $PDOInstance and call setPdoInstance() method.

Latest Blog


PHP – 8.0 Match Expression

In PHP 8.0 there is a new feature or I should say a new language construct (keyword) going to be introduced,  which has been implemented depending […]


New Union Type in PHP – 8

A new RFC has been finished voting and accepted for PHP – 8. That is “Union Types”, which is an extension of PHP’s type system. […]