Setter and getter generator for PHP, JavaScript, C++ and C#

Edited 02. Dec 2010, 14:24
Published 10. Nov 2010, 15:09
Files setnget_gen.php
Pages
  1. Setter and getter form
  2. Setter and getter function for PHP (for offline use)

Here is an online-based setter and getter generator tool capable of generating setters and getters for multiple programming languages, including PHP, JavaScript, C++ and C#. Simply choose the language of your preference, write the property names and click the generator button. Voilà!

Here's how you use it (read tutorial here):
1. Write the property names (ie. foo) seperated by a newline in the corresponding box.
2. Click the generate button.
3. Copy + paste the result into your class.

Options

(?)

Argumentlist

(?)

Arguments are seperated by a pipe symbol (|).
Example: 'foo|bar' yields two arguments, foo and bar.

Type shorthands (for strongtyped languages)

  • s = string
  • i = int
  • b = bool
  • f = float

Tutorial

Your first step in generating the setters and getters is to write the names of the properties in the "properties" box. One property per line. After you're done inserting the property names your are ready to generate the setters and getters. Do so by pressing the generate button. The resulting output should be shown in the "Output" box, so now you can simply copy+paste the result into your own class.

You can make adjustments in the options to tailor the output for your own preferences. When specifying properties you can also add so called arguments. Arguments are used to customize the property output on a per property level. Read more about them in the arguments section.

Options

Format mode: Customize the format of the setter and getter methods.
Mode (for JS): Specify whether to generate setters and getters for dynamic or static objects.
Default type (strongtyped languages): The default type to be used if type is not given as argument.
Default access level: The default access level to be used if level is not given as argument.
Property positions: You can choose whether you want the properties to be seperated from, above or below the setter and getter definitions.

Arguments

Properties can be customized on a per property level by using arguments. Usually only specifying the property name is sufficiant for most cases, but for extra convinience it's possible to pass extra arguments and tailor the output further.

The property name itself is a single argument and is naturally a required argument. Extra arguments can be passed by using the pipe symbol (|) as a delimiter, like this: foo|bar. Here foo is the first argument and bar is the second argument.

Arguments can be skipped by simply including the delimiter but not writing any value as argument, like this: foo||bar. The second argument is here skipped and the default value is used.

Files

View Source: setnget_gen.php
Download: setnget_gen.php

Back to the top