<?php
header('Content-Type:text/html;charset=utf-8');
class Humanity {
  public $name;
  public $sex;
  public $iq=10;
  const BIRTHPLACE='地球';
  //构造函数
  public function __construct($name,$sex){
    $this->name=$name;
    $this->sex=$sex;
  }
  protected function chew($food){
    echo "<p>{$food}已经被咀嚼完成!</p>";
  }
  public function eat($food){
    $this->chew($food);
    echo "<p>{$this->name}正在吃{$food}!</p>";
  }
  public function hello(){
    echo '<p>您好!我是来自'.self::BIRTHPLACE.'的人类</p>';
  }
}
class Student extends Humanity {
  const BIRTHPLACE='火星';
  public $studentId;
  public function test($subject){
    echo "<p>{$this->name}正在考{$subject}!</p>";
  }
  public function eat($food){
    $this->chew($food);
    echo "<p>{$this->name}正在快速的吃{$food}!</p>";
  }
  public function hello(){
    parent::chew('铅笔');//没有必要通过这种方式来访问,因为他以及被你继承过来了!
    parent::hello();
    echo '<p>您好!我是来自'.self::BIRTHPLACE.'人类中的学生</p>';
  }
}
echo '<p>'.Humanity::BIRTHPLACE.'</p>';
echo '<p>'.Student::BIRTHPLACE.'</p>';
//$hanMM=new Humanity('韩梅梅','女');
//$hanMM->hello();
$liLei=new Student('李雷','男');
$liLei->hello();
echo $liLei::BIRTHPLACE;//可以,但是我们极度不建议你通过具体的实例去访问 类常量解析:
**范围解析操作符::
作用:
一、访问类里面的静态成员
二、访问类里面的常量
类内部如果访问?
self::类常量名称
parent::类常量名称
类外部如果访问?
  类名称::类常量名称
  注意点:需要访问那个类里面的常量就用哪个类的名称就可以了三、在子类里面访问父类中的方法(被重写了的方法)
parent::方法
我们没有必要在子类里面通过parent去访问父类中 没有被 重写 的方法!
注意:类常量可以在子类中重写去定义、但是不能直接修改其值!**
效果:











