Advertisement
Nikita051

Untitled

Nov 6th, 2022
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2.     class User
  3.     {
  4.         private $name;
  5.         private $age;
  6.            
  7.         public function __set($property,$value){
  8.             switch($property){
  9.                 case 'name':
  10.                     if($value != ''){
  11.                         $this -> $property = $value;
  12.                     }
  13.                 break;
  14.                 case 'age':
  15.                     if($value >= 0 && $value<= 70){
  16.                         $this -> $property = $value;
  17.                     }
  18.                 break;
  19.             }
  20.         }
  21.         public function show(){
  22.             return $this -> name." ".$this -> age;
  23.         }
  24.         public function __get($property){
  25.             return $this -> property;
  26.         }
  27.     }
  28.     $user = new User;
  29.     $user -> name = "Nikita";
  30.     $user -> age = 17;
  31.     echo $user -> name;
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement