zoukankan      html  css  js  c++  java
  • About_类与对象03

    php中的static

    1:属于静态变量:;

    2:是全部类的属性;

    3:调用静态变量要用::(两个冒号)。

    eg:1

     1 <html>
     2 <head>
     3     <title>static测试</title>
     4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
     5 </head>
     6 <body>
     7 <?PHP
     8 class Person{
     9 
    10     static $type = "人物";
    11     public $name = "张三";
    12     public $age = 18;
    13 
    14     public function intro(){
    15         echo Person::$type."<br/>".$this->name."<br/>".$this->age."<br/>";
    16     }
    17 }
    18 
    19 $p1 = new Person();
    20 
    21 $p1->intro();
    22 ?>
    23 </body>
    24 </html>

    eg:2

     1 <html>
     2 <head>
     3     <title>static测试</title>
     4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
     5 </head>
     6 <body>
     7 <?PHP
     8 class Person{
     9 
    10     static $type = "人物";
    11     public $name = "张三";
    12     public $age = 18;
    13 
    14     public function intro(){
    15         echo Person::$type."<br/>".$this->name."<br/>".$this->age."<br/>";
    16     }
    17 }
    18 
    19 $p1 = new Person();
    20 Person::$type = "张三不是人!";
    21 
    22 $p1->intro();
    23 ?>
    24 </body>
    25 </html>

    eg:3

    class类的继承

     1 <html>
     2 <head>
     3     <title>class类的继承</title>
     4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
     5 </head>
     6 <body>
     7 <?PHP
     8 class Person{
     9 
    10     static $type = "人物";
    11     public $name = "张三";
    12     public $age = 18;
    13 
    14     public function intro_Person(){
    15         echo $this->name."<br/>".$this->age."<br/>";
    16     }
    17 }
    18 
    19 class Teacher extends Person{
    20 
    21     public function intro_Teacher(){
    22         echo $this->age;
    23     }
    24 
    25 }
    26 
    27 class Students extends Teacher{
    28 
    29     public function intro_Students(){
    30         echo $this->age;
    31     }
    32 
    33 }
    34 
    35 $p1 = new Students();
    36 
    37 $p1->intro_Students();
    38 ?>
    39 </body>
    40 </html>
  • 相关阅读:
    winform_webApiSelfHost
    手机访问网站自动跳转到手机版
    Linux常用命令
    css居中
    固定菜单
    BOM操作写法实例
    表格(合并单元格)
    倒计时
    分享到插件
    jquery获得下拉框的值
  • 原文地址:https://www.cnblogs.com/a-moemiss/p/3746627.html
Copyright © 2011-2022 走看看