Last active
February 24, 2020 22:09
-
-
Save dogmatic69/4498743 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class Php53Traits { | |
public function __call($name, $params) { | |
if(!isset($this->{$name}) || !gettype($this->{$name}) == 'object') { | |
throw new Exception('not found'); | |
} | |
$tmp = $this->{$name}; | |
return call_user_func_array($tmp, $params); | |
} | |
} | |
$Class = new Php53Traits(); | |
$Class->test = function ($text) { | |
var_dump($text); | |
}; | |
$Class->test('hello world'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hacking traits into php5.3 with closures example