Skip to content

Instantly share code, notes, and snippets.

@gabrieljmj
Last active August 29, 2015 14:15
Show Gist options
  • Save gabrieljmj/ae7b69e268036403e457 to your computer and use it in GitHub Desktop.
Save gabrieljmj/ae7b69e268036403e457 to your computer and use it in GitHub Desktop.
Hidding static methods
<?php
use App\User;
$u = new User();
$u->setName('Gabriel');
$u2 = new User();
$u2->getName(); //Gabriel
<?php
namespace Gabrieljmj;
trait HideStaticMethods
{
public function __call($method, $args)
{
return foward_static_call_array(array(self, $method), $args);
}
}
<?php
namespace App;
class User
{
use \Gabrieljmj\HideStaticMethods;
private static $name;
public static function setName($name)
{
self::$name = $name;
}
public static function getName()
{
return self::$name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment