PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- class nameExc extends Exception {
- function __construct($msg){
- $msg.= " name!";
- parent::__construct($msg);
- }
- }
- class loginExc extends Exception {
- function __construct($msg){
- $msg.=" login";
- parent::__construct($msg);
- }
- }
- class passExc extends Exception {
- function __construct($msg){
- $msg.=" password";
- parent::__construct($msg);
- }
- }
- abstract class AUser{
- abstract function showInfo();
- }
- class User extends AUser{
- const INFO_TITLE="Данные пользователя: ";
- public $name;
- public $login;
- public $pass;
- function __construct($n="",$l="",$p=""){
- try{
- if($n==""){
- throw new nameExc ("Введите:");
- }
- $this->name=$n;
- if($l==""){
- throw new loginExc("Введите:");
- }
- $this->login=$l;
- if($p==""){
- throw new passExc("Введите:");
- }
- $this->pass=$p;
- }catch(nameExc $e){
- echo $e->getMessage();
- }catch(loginExc $e){
- echo $e->getMessage();
- }catch(passExc $e){
- echo $e->getMessage();
- }
- }
- function __clone(){
- $this->name="Guest";
- $this->login="quest";
- $this->pass="qwery";
- }
- function showInfo(){
- echo "<p>Name : ".$this->name."<br>";
- echo "Login : ".$this->login."<br>";
- echo "Password : ".$this->pass."<br>";
- }
- function showTitle(){
- echo "<h3>".self::INFO_TITLE."<h3>";
- }
- }
- interface ISuperUser{
- function getInfo();
- }
- class SuperUser extends User implements ISuperUser {
- public $role;
- function __construct($n,$l,$p,$r){
- parent::__construct($n,$l,$p);
- $this->role=$r;
- }
- function showInfo(){
- parent::showInfo();
- echo "Role : ".$this->role."<br>";
- }
- function getInfo(){
- foreach($this as $k->$v){
- $arr[$k] = $v;
- }
- return $arr;
- }
- }
- $user1= new User("Vasya","V","password");
- $user1->showTitle();
- $user1->showInfo();
- $user2= new User("Petya","P","1234");
- $user2->showTitle();
- $user2->showInfo();
- $user3= new User("Sasha","S","63445sgf");
- $user3->showTitle();
- $user3->showInfo();
- $user4 = clone $user1;
- $user4->showTitle();
- $user4->showInfo();
- $user5 = new superUser("Dasha","D","3213444","admin");
- $user5->role="admin";
- $user5->showTitle();
- $user5->showInfo();
- ?>