Skip to content
Stefano Azzolini edited this page Aug 29, 2014 · 1 revision

The Module trait provides a way to extend classes, even static with new methods.

Extend a class with new methods


class Test {
  use Module;
  public static function Foo(){ echo "Foo"; }
}

Test::Foo(); // Foo
Test::Bar(); // Fatal error: Call to undefined method Test::Bar

Test::extend([
  'Bar' => function(){ echo "Bar"; },
]);

Test::Bar(); // Bar
Clone this wiki locally