PHP Classes

Access Methods: Map variable accesses to accessor method calls

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Info   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2006-07-19 (9 years ago) RSS 2.0 feedNot enough user ratingsTotal: 1,161 All time: 3,084 This week: 1,144Up
Version License Categories  
accessmethods 1.0BSD LicensePHP 5, Language
Description Author  

This class can be used to map accesses to class variables into calls to setter and getter methods.

It provides functions that can called from a class __set and __get methods to automatically set or get the property values by calling the class setter and getter methods for the respective properties.

For example, if there is a property named "name", the class accessor methods usually are named of "getName" and "setName". Accesses to $object->name property are mapped to $object->setName($value) and $object->getName() calls.

Innovation Award  
PHP Programming Innovation award nominee
July 2006
Number 7
Some authors prefer to encapsulate the access to the properties of objects of a class using setter and getter functions and making the property variables private.

This approach allows allows changing the implementation of the access to the properties without changing the interface of the class.

Despite the advantages of this approach, many users prefer the variable assignment syntax to set or get the property values, as it is less tedious.

This class makes possible to use the variable assignment syntax to access the properties while keeping the setter and getter approach.

It takes advantage of the PHP 5 special class functions __set and __get functions and the reflection API to determine which functions should be called set or get property values.

Manuel Lemos
Picture of Olavo Alexandrino
Name: Olavo Alexandrino <contact>
Classes: 8 packages by
Country: Brazil Brazil
Age: 34
All time rank: 835 in Brazil Brazil
Week rank: 644 Down49 in Brazil Brazil Down
Innovation award
Innovation award
Nominee: 1x

  Files folder image Files  
File Role Description
Accessible without login Plain text file test.php Example An example of use
Plain text file class.AccessMethods.php Class The AccessMethods class

 Version Control Unique User Downloads Download Rankings  
 0%Total:1,161All time:3,084
 This week:0This week:1,144Up
 User Comments (1)  
6 years ago (kishore kumar)