Advertisement
Nikita051

Untitled

Oct 3rd, 2022
1,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2.     class User{
  3.         private $name;
  4.         private $age;
  5.  
  6.         public function getName(){
  7.             return $this -> name;
  8.         }
  9.         public function setName($name){
  10.             if(preg_match("#.{3,}#",$name)){
  11.                 $this -> name = $name;
  12.             }
  13.         }
  14.         public function getAge(){
  15.             return $this -> age;
  16.         }
  17.         public function setAge($age){
  18.             $this -> age = $age;
  19.         }
  20.     }
  21.     class Student extends User{
  22.         private $kurs;
  23.        
  24.         public function getKurs(){
  25.             return $this -> kurs;
  26.          }
  27.         public function setKurs($kurs){
  28.             $this -> kurs = $kurs;
  29.         }
  30.         public function addOneYear(){
  31.             $this -> age++;
  32.         }
  33.         public function setName($name){
  34.             if(preg_match("#.{0,10}#",$name)){
  35.                 parent::setName($name);
  36.             }
  37.         }
  38.     }
  39.     $student = new Student;
  40.     $student -> setName("aaaaaaaaaaaaaaaa");
  41.     echo $student -> getName();
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement