Last active
August 29, 2015 14:15
-
-
Save gabrieljmj/ae7b69e268036403e457 to your computer and use it in GitHub Desktop.
Hidding static methods
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 | |
use App\User; | |
$u = new User(); | |
$u->setName('Gabriel'); | |
$u2 = new User(); | |
$u2->getName(); //Gabriel |
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 | |
namespace Gabrieljmj; | |
trait HideStaticMethods | |
{ | |
public function __call($method, $args) | |
{ | |
return foward_static_call_array(array(self, $method), $args); | |
} | |
} |
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 | |
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