$sessionName) {} public function close() {} public function read($id) {} public function write($id, $data) {} public function destroy($id) {} public function gc($maxlifetime) {} } $handler = new MySessionHandler(); session_set_save_handler($handler, true); session_start();
'/tmp/log');} } trait Log { use File; public function addLog($m) {$this->put('LOG: '.$m);} } class Test { use Log; public function foo() { $this->addLog('test');} } $obj = new Test; $obj->foo(); //return LOG: test
Game";} } trait Music { public function play() {return "Play Music";} } class Player { use Game, Music; } $o = new Player; echo $o->play(); Solving confict PHP does not solve conflicts automatically PHP Fatal error: Trait method play has not been applied, because there are collisions with other trait methods on Player in /var/www/test/test_traits.php on line 10
Game";} } trait Music { public function play() {return "Play Music";} } class Player { use Game, Music { Game::play as gamePlay; Music::play insteadof Game; } } $o = new Player; echo $o->play(); //return Play Music echo $o->gamePlay(); //return Play Game