Skip to content

Instantly share code, notes, and snippets.

@DavidMikeSimon
Forked from evillemez/gist:8735382
Last active August 29, 2015 13:55
Show Gist options
  • Select an option

  • Save DavidMikeSimon/8738363 to your computer and use it in GitHub Desktop.

Select an option

Save DavidMikeSimon/8738363 to your computer and use it in GitHub Desktop.
<?php
trait Methods
{
public function __call($name, $args)
{
if (property_exists($this, $name)) {
return $this->$name;
}
if (get_parent_class($this)) {
return parent::__call($name, $args);
}
return null;
}
}
class Person
{
use Methods;
private $pPrivate = 'pPrivate';
protected $pProtected = 'pProtected';
public $pPublic = 'pPublic';
}
class Salesman extends Person
{
use Methods;
private $sPrivate = 'sPrivate';
protected $sProtected = 'sProtected';
public $sPublic = 'sPublic';
}
$dude = new Salesman();
var_dump($dude->sPublic());
var_dump($dude->sProtected());
var_dump($dude->sPrivate());
var_dump($dude->pPublic());
var_dump($dude->pProtected());
var_dump($dude->pPrivate());
var_dump($dude->weirdthing()); # No such variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment