PHP Classes

PHP Property Preprocessor: Preprocess class variables when they are accessed

Recommend this page to a friend!
  Info   View files Documentation   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 100 All time: 9,684 This week: 213Up
Version License PHP version Categories
prop-preprocessor 1.0.1MIT/X Consortium ...5PHP 5, Data types, Language, Traits


This package can preprocess class variables when they are accessed.

It provides a trait that implements a getter function defined by the __get function.

This trait getter function can parses the name of the variable that is being accessed and calls a function with the same name of the last part of the variable name to process the actual variable value before it is returned.

Innovation Award
PHP Programming Innovation award nominee
October 2018
Number 5
PHP supports using class functions named __get to implement a single function that will be used to return values of any class variables.

This package provides a trait that provides a getter function that can preprocess the value of a variable being retrieved in a way that is defined by a custom function.

Manuel Lemos
Picture of Mahesh S
  Performance   Level  
Name: Mahesh S <contact>
Classes: 3 packages by
Country: India India
Age: 33
All time rank: 3937272 in India India
Week rank: 503 Up42 in India India Up
Innovation award
Innovation award
Nominee: 2x


Property Value Pre-processor for PHP

This is a simple yet powerful trait which allows one to easily pre-process the properties before they are returned from the objects of classes which use it.


The preferred way to install this extension is to click here which will download the package as a zip file. Instructions on how to use it is explained below.

How to use

From the downloaded zip, place the file PreProcessorTrait.php in your project's 'traits' folder(please create one if it does not exist). In your classes, you can use the trait as below:

class ClassName{
use \traits\PreProcessorTrait.php

Use Cases

Suppose you have an object $store and it has a property $products which is an array of all the Product objects in that Store.

The Product objects are too large and it contains lot of data and you currently need only some minimal data.

Use PreProcessorTrait in the $store object's class as explained above and insert the following method in traits\PreProcessorTrait.php

public function getMinified($objects){
		foreach($objects as &$object){
		return $objects;

public function minify(){
    //your logic to minify and return the object

You can get the minified data by calling like this: $store->productsMinified. Similarly you can use like this for any property of the $store object. Eg:- $store->invoicesMinified, $store->customersMinified etc.

From this point on, any class using the PreProcessorTrait will have the ability to minify it's properties before returning them.

For example:


Like this, you can add whatever methods in PreProcessorTrait and it can be used in any object in which this trait is used in the very same way explained above. For more use cases and examples, click here

  Files folder image Files  
File Role Description
Accessible without login Plain text file Doc. Examples code
Accessible without login Plain text file LICENSE Lic. License text
Plain text file PreProcessorTrait.php Class Class source
Accessible without login Plain text file Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,684
This week:213Up