Skip to content

Instantly share code, notes, and snippets.

@dominikzogg
Created March 23, 2012 21:21
Show Gist options
  • Save dominikzogg/2175184 to your computer and use it in GitHub Desktop.
Save dominikzogg/2175184 to your computer and use it in GitHub Desktop.
trait test
<?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