php继承

<?php

header("Content-type:text/html;charset=utf-8");

class family {

    public $name;
    public $age;

    public function __construct() {
        echo "父类构造函数<br>";
    }

    public function say() {
        echo "父类" . $this->name . "今年," . $this->age;
    }

}

class sun extends family {

    public $name; //与父类属性同名将覆盖父类的name
    public $age;

    public function __construct() {
        parent::__construct();
        echo "子类构造函数<br>";
    }

    public function sayddd() {
        $this->name = "ddddd";
        $this->age = 222;
        $this->say();
    }

}

$sun = new sun();
$sun->sayddd();

  

posted @ 2015-12-17 12:03  等待是一生最初的苍老  阅读(107)  评论(0编辑  收藏  举报