<?php
class Teacher{
public $p1 = 1;
var $p2 ;
public $name = ' 匿名';
public function introMe(){
echo '<pre>';
echo '<br/>属性p1:'.$this->p1;
echo '<br/>属性p2:'.$this->p2;
echo '<br/>姓名:'.$this->name;
echo '</p>';
}
}
$t1 = new Teacher();
$t1->introMe();
class Student{
const SCHOOL = '传志';
public $name = '施超';
var $age = 0;
public $sex='男';
static $count = 33;
function __construct($name,$age=0,$sex='男'){
$this->name = $name;
$this->age = $age;
$this->sex = $sex;
self::$count++;
echo "{$name}加入传志,当前有".self::$count."个学生 ";
}
public function introMe(){
echo '<pre>';
echo '<br/>姓名:'.$this->name;
echo '<br/>性别:'.$this->age;
echo '<br/>年龄:'.$this->sex;
echo '</p>';
}
function __destruct(){
echo "<br/>{$this->name}被销毁" ;
}
}
$t1 = new Student('weigang',23);
$t1->introMe();
$t1 = new Student('hehe',23);
$t1->introMe();
$t2 = new Student('hehehehe',23);
$t2->introMe();