php面向對象二之封裝,protected ,public,private權限管理

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>封裝的概念</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
    <body>
        <?php 
        // 1.封裝,2,重載
        /**
        * 
        */
        class People
        {     
            //對屬性的封裝 
            //對方法的封裝 
            private $memony=1000;
            public function share(){
                echo $this->memony;
            }
        }
        $peo=new People();
        //private私有,不能夠調用
        $peo->share();

        ?>
    </body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>private私有權限</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
    <body>
        <?php 
        // private權限修飾符, protected保護的,public公共的
        class Human{
            private $money=1000;
        public function showmoney(){
            return $this->money;}
        }
        $p=new Human();
        echo $p->showmoney();
        ?>
    </body>
</html>
相關文章
相關標籤/搜索