Created
March 23, 2012 21:21
-
-
Save dominikzogg/2175184 to your computer and use it in GitHub Desktop.
trait test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class BaseUser | |
{ | |
protected $id; | |
public function getId() | |
{ | |
return $this->id; | |
} | |
} | |
trait UserExtension1 | |
{ | |
protected $username; | |
public function getUsername() | |
{ | |
return $this->username; | |
} | |
public function setUsername($username) | |
{ | |
$this->username = $username; | |
return $this; | |
} | |
} | |
trait UserExtension2 | |
{ | |
protected $password; | |
public function getPassword() | |
{ | |
return $this->password; | |
} | |
public function setPassword($password) | |
{ | |
$this->password = md5($password); | |
return $this; | |
} | |
} | |
class User extends BaseUser | |
{ | |
use UserExtension1; | |
use UserExtension2; | |
} | |
$user = new User(); | |
$user->setUsername('filip.janecek'); | |
$user->setPassword('zasZas-asd'); | |
printdata($user); | |
function printdata($data) | |
{ | |
echo '<pre>'; | |
print_r($data); | |
echo '</pre>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment