构造方法__construct初始化并赋值实例化(PHP基础教程)
- <?php
- class ZhaoPin{
- public $name;
- public $age;
- public $sex;
- public $height;
-
- function __construct($name,$age,$sex,$height){ //自动执行 构造方法 初始化对象
- $this->name = $name;
- $this->age = $age;
- $this->sex = $sex;
- $this->height = $height;
- }
-
- function ziDiu(){
- if($this->age >18 && $this->height >160){
- return $this->name .'符合招聘条件。';
- }else{
- return $this-name .'不符合招聘条件';
- }
- }
- }
- $ziDiuZhaoPin = new ZhaoPin('自丢','26','男','178');
- echo $ziDiuZhaoPin->ziDiu();
复制代码 PHP源码运行结果图:
构造方法__construct初始化并赋值实例化(PHP基础教程)
|