<?php
header("Content-type:text/html;charset=utf-8");
/*封装
目的:为了使类更加安全
做法:
1.将成员变量变成私有
2.做一个成员方法来间接访问
3.在该方法里面加限制条件
450147805
class Ren
{
private $age; //public (公有) private (私有) 18s岁-50岁之间
function setAge($n)
{ if($n>=18 && $n<=50)
{
$this->Age = $n;
}
}
function getAge()
{
return $this->age;
}
}
class Ren
{
private $age;
private $name;
function __set($n,$v){
if($v>=18 && $v<50){
$this->$n = $v;
}
else{
$this->$n = $v;
}
}
}
$r = new Ren();
$r->setName("张三");
var_dump($r);
echo $r->getname();
$r = new Ren;
$r->__set("age",20);
$r->name = ("张三");
var_dump($r);*/
//继承
//子类可以继承父类的一切
//
//
class Ren{
private $name;
function Run()
{
echo "跑步";
}
}
class Nan extends Ren ( extends =继承)
{
function Run()
{
parent ::Run();//
echo "洗澡";
}
}
$c = new Nan();
$c->Run();
?>