Blogger Information
Blog 18
fans 0
comment 0
visits 14910
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php 类的权限
牛粪也香的博客
Original
1116 people have browsed it

image.png

image.png

结果:

image.png

image.png

image.png

image.png

image.png

image.png

代码:

<?phpnamespace admin;

class People{

//类中成员,包括: 属性和方法;

 private $age;//属性,私有的属性

protected $phone;//属性,保护的属性

public function getage()

{

 return $this->age;

 }

 public function __construct($age,$phone)

 {  $this->age=$age;//把第一个参数 赋值给age属性 

 $this->phone=$phone;//把第一个参数 赋值给phone属性

  }

 public function age() { return $this->age; }  

 public function phone() {

 return $this->phone;

}

}

//权限管理 

 $obj = new People('18','13888888'); 

 echo $obj->age(); 

 // echo "<hr>";  

 echo $obj->phone();   

// $obj->age;   // $obj->phone;echo "<hr>"; 

  class per extends People   {   

 public function display()   

 {   

 return $this->phone;  

  }  

 }   

$obj =new per(28,13666666);  

 echo $obj->display();

//总结://private 的属性或方法,只有在本类中,可以进行相关的调用//protected 的属性或方法,除了在本类中可以调用之外, 在子类中也可以调用//public 的属性或方法,都可以调用

Correction status:qualified

Teacher's comments:作业很认真, 代码写得也规范
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post