Skip to content

Instantly share code, notes, and snippets.

@dogmatic69
Last active February 24, 2020 22:09
Show Gist options
  • Select an option

  • Save dogmatic69/4498743 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
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