类的声明和使用

原创2018-12-20 17:18:5145
摘要:类和对象的定义,类中成员属性和常量的使用,类的自动加载机制,类的封装机制。<?phpclass Sport{    public $name;    public $height;    public $age;    public $sex;    public function __con

类和对象的定义,类中成员属性和常量的使用,类的自动加载机制,类的封装机制。


<?php

class Sport{
   public $name;
   public $height;
   public $age;
   public $sex;
   public function __construct($name,$height,$age,$sex)
   {
       $this->name=$name;
       $this->height=$height;
       $this->age=$age;
       $sex->sex=$sex;
   }

   public function basketBall(){
       if($this->height>'190'){
           return $this->name."符合打篮球要求";
       }else{
           return $this->name."不符合打篮球要求";
       }
   }

}

$sport=new Sport("姚明",'220',"30","男");
$sport->basketBall();


?>

批改老师:天蓬老师批改时间:2018-12-20 17:27:59
老师总结:没看到你的封装呀, 封装是不允许使用public的

发布手记

热门词条