class ExampleParent { private $hello_world = "hello foo\n"; public function foo() { echo $this->hello_world; } } class Example extends ExampleParent { use ExampleTrait; } trait ExampleTrait { /** * */ private $hello_world = "hello bar\n"; /** * */ public $prop = "ops"; public function bar() { echo $this->hello_world; } } $x = new Example(); $x->foo(); $x->bar();
<?php class Example { function foo() { echo "this is foo\n"; } function bar() { echo "this is bar\n"; } function __call($name, $args) { echo "tried to handle unknown method {$name}\n"; if ($args) { echo "it had arguments: ", implode(', ', $args), "\n"; } } } $example = new Example(); $example->foo(); // prints "this is foo" $example->bar(); // prints "this is bar" $example->grill(); // prints "tried to handle unknown method grill" $example->ding("dong"); // prints "tried to handle unknown method ding" // prints "it had arguments: dong
<?php class Example { function foo() { return "foo!\n"; } } // Rename the 'foo' method to 'bar' runkit_method_rename('Example', 'foo', 'bar'); // output renamed function echo Example::bar();