Login   Register  
PHP Classes

C# getters and setters in PHP: Access class variables with setters and getters

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2011-08-11 (3 years ago) RSS 2.0 feedNot enough user ratingsTotal: 524 All time: 5,172 This week: 1,379Up
Version License PHP version Categories  
csharp-getter-setter 1.0BSD License5.0PHP 5, Data types, Language
Description Author  

This package can access class variables with setter and getter functions.

It provides a base class with __set, __get, __isset, __unset functions that store the variable values in an associative array.

Sub-classes can declare and initialize the values of the class variables so IDE and other documentation extraction tools can still find the variables declared by the class.

Another class is also provided to make the access to class variables a read-only operation, so attempts to alter or unset a class variable throws an exception.

Sub-classes can initialize the values of variables by assigning values to variables with the same names but starting with an underscore character (_).

Innovation Award  
PHP Programming Innovation award nominee
August 2011
Number 4

Prize: One copy of the Zend Studio
Setters and getters are functions that can store and retrieve values of class variables. They encapsulate the access to variables, so applications have no direct access to the class variable values.

Classes defined with setter and getter functions often store variables in private arrays or some other opaque data access method. However, this approach prevents IDE or other documentation editing tools to reverse engineer a class definition to know about its variables.

This class provides a solution for this problem by letting developers define simulated variable declarations that IDE and documentation tools can extract, while preserving the encapsulation of the access to the class variable values via the getter and setter functions.

Manuel Lemos
Picture of Artur Graniszewski
Name: Artur Graniszewski is available for providing paid consulting. Contact Artur Graniszewski .
Classes: 13 packages by
Country: Poland Poland
Age: 32
All time rank: 3285 in Poland Poland
Week rank: 154 Up5 in Poland Poland Equal
Innovation award
Innovation award
Nominee: 7x

Winner: 1x

  Files folder image Files  
File Role Description
Plain text file magic.php Class Library
Accessible without login Plain text file read_only_property.php Example Example: marks all properties with an underscore as the first letter of their names as a read-only
Accessible without login Plain text file readme.txt Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 0%Total:524All time:5,172
 This week:0This week:1,379Up
 User Comments (1)  
interesting theoretical approach
3 years ago (Grigori Kochanov)