命名空间namespace 创建类 class
<?php
//命名空间
namespace my\name;
//创建类
class a{
public $name = '张三';
public $age =18;
public function get(){
echo $this->name . '在吃饭';
}
}
//实例化类:
$obj= new \my\name\a;
$obj->get();
成员变量、成员方法
<?php
// 成员变量、成员方法
class spObj{
public $name;
public $height;
public $avo;
public function bootFootBall($name,$height,$avo){
$this->name=$name;
$this->height=$height;
$this->avo=$avo;
if($this->height<185 and $this->avo <85){
return $this->name .';符合踢足球的要求!';
}else{
return $this->name .';不符合踢足球的要求!';
}
}
}
$obj=new spObj();
echo $obj->bootFootBall('张三','185','80');
构造方法
<?php
// 构造方法
class spObj{
public $name;
public $height;
public function __construct($name,$height){
$this->name=$name;
$this->height=$height;
}
public function shuchu(){
echo $this->name . '的身高是' . $this->height ;
}
}
$spObj=new spObj('张三','185');
$spObj->shuchu();