翻身的废鱼——论PHP从入门到放弃需要多久?19
2021-06-07 04:03
标签:php初学者 今日课程:PHP开发-零基础到精通疯狂实战教程(第二季)【韦玮老师】 1.继承与封装的实战
本文出自 “一条大大大大废鱼” 博客,谢绝转载! 翻身的废鱼——论PHP从入门到放弃需要多久?19 标签:php初学者 原文地址:http://lonelyman.blog.51cto.com/9706318/1954951/*封装*/
class woman{
var $name;
var $age;
private $money;//给money赋值
function setm($b){
$this->money=$b;
}
function money1(){
echo ‘my money is‘.($this->money).‘
‘;
}
}
$a = new woman();
$a ->name;
//$a ->money;无法访问
//$a ->money1();可以正常访问
//$a ->money1();无法访问
$a ->setm(999);
$a ->money1();/*继承*/
class woman{
var $name;
var $age;
function ect(){
echo "i can eat
";
}
}
class man extends woman{
function sing(){
echo ‘i cam sang
‘;
}
}
class ren extends man{
}
$a = new man();
$a -> ect();
$a -> sing();
$b = new ren();
$b -> ect();
$b -> sing();/*重载*/
class woman{
var $name;
var $age;
function eat(){
echo "i can eat
";
}
}
class ren extends woman{
function eat(){
echo ‘i can 大口吃
‘;
}
}
$a = new ren();
$a -> eat();//重载方法