Instantly share code, notes, and snippets.

Embed
What would you like to do?
Trait for making protected/private attributes "gettable", leaving "setting" the attributes a matter of business logic to be implemented.
<?php
trait Gettable {
/**
* Retrieve private attributes.
* Attributes should be protected
* so they cannot be *set* arbitrarily.
* This allows us to *get* them as if they
* were public.
* @param String $key
* @return mixed
*/
public function __get($key)
{
if( property_exists($this, $key) )
{
return $this->$key;
}
}
}
@IsraelOrtuno

This comment has been minimized.

IsraelOrtuno commented Feb 14, 2015

Using this for testing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment