-
-
Save cookstaar/d49c1de73a0fd30e49bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment