Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User
- {
- private $name;
- private $age;
- public function __set($property,$value){
- switch($property){
- case 'name':
- if($value != ''){
- $this -> $property = $value;
- }
- break;
- case 'age':
- if($value >= 0 && $value<= 70){
- $this -> $property = $value;
- }
- break;
- }
- }
- public function show(){
- return $this -> name." ".$this -> age;
- }
- public function __get($property){
- return $this -> property;
- }
- }
- $user = new User;
- $user -> name = "Nikita";
- $user -> age = 17;
- echo $user -> name;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement