Skip to content

Instantly share code, notes, and snippets.

@dogmatic69
Last active February 24, 2020 22:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogmatic69/4498743 to your computer and use it in GitHub Desktop.
Save dogmatic69/4498743 to your computer and use it in GitHub Desktop.
<?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');
@dogmatic69
Copy link
Author

Hacking traits into php5.3 with closures example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment