Skip to content

Instantly share code, notes, and snippets.

@emmanuelbarturen
Last active November 22, 2017 16:30
Show Gist options
  • Save emmanuelbarturen/91e5081f9ce72da7d971f30c60049641 to your computer and use it in GitHub Desktop.
Save emmanuelbarturen/91e5081f9ce72da7d971f30c60049641 to your computer and use it in GitHub Desktop.
Create Accesors like laravel in object
class TheAttribute
{
public function __get($name)
{
$name = array_map('ucfirst', explode('_', $name));
$name = implode($name);
# use echo instead return if is not a framework
return $this->{'get' . $name . 'Attribute'}();
}
public function getTheNameAttribute()
{
return 'Emmanuel Barturen';
}
}
(new TheAttribute())->the_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment