码迷,mamicode.com
首页 > Web开发 > 详细

PHP受保护的类和私有类什么区别

时间:2016-09-20 11:50:18      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

受保护的继承后可以访问,私有的只能在该类中访问,不会被继承访问
class Man{
protected $name=‘lee‘;//受保护
private $age=123;//私有
function __construct(){
echo $this->name;//lee
echo $this->age;//123

}

}
class Girl extends Man{
function __construct(){
echo $this->name;//lee
echo $this->age;//不会出现123,

}

}

new Man();

new Girl();


<?php
class Man{
    protected $name=‘lee‘;//受保护
    private    $age=123;//私有
    function __construct(){
        echo $this->name;//lee
        echo $this->age;//123

    }

}
class Girl extends Man{
    function __construct(){
        echo $this->name;//lee
        echo $this->age;//不会出现123,

    }

}

new Man();

new Girl();

技术分享

PHP受保护的类和私有类什么区别

标签:

原文地址:http://www.cnblogs.com/hellowzd/p/5887945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!