PHP Classes

Access Methods: Map variable accesses to accessor method calls

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 56%Total: 1,172 All time: 3,233 This week: 455Up
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: 43
All time rank: 885 in Brazil Brazil
Week rank: 170 Down12 in Brazil Brazil Down
Innovation award
Innovation award
Nominee: 1x

  Files folder image Files (2)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:1,172
This week:0
All time:3,233
This week:455Up
User Ratings User Comments (1)
 All time
Utility:81%StarStarStarStarStar
Consistency:81%StarStarStarStarStar
Documentation:-
Examples:75%StarStarStarStar
Tests:-
Videos:-
Overall:56%StarStarStar
Rank:1825
 
Excellent
15 years ago (kishore kumar)
70%StarStarStarStar