构造方法__construct初始化并赋值实例化(PHP基础教程)

[复制链接]
查看2892 | 回复1 | 2019-3-25 09:43 | 显示全部楼层 |阅读模式
构造方法__construct初始化并赋值实例化(PHP基础教程)
  1. <?php
  2. class ZhaoPin{
  3.         public $name;
  4.         public $age;
  5.         public $sex;
  6.         public $height;
  7.         
  8.         function __construct($name,$age,$sex,$height){   //自动执行 构造方法 初始化对象
  9.                 $this->name = $name;
  10.                 $this->age = $age;
  11.                 $this->sex = $sex;
  12.                 $this->height = $height;
  13.         }
  14.         
  15.         function ziDiu(){
  16.                 if($this->age >18 && $this->height >160){
  17.                         return $this->name .'符合招聘条件。';
  18.                 }else{
  19.                         return $this-name .'不符合招聘条件';
  20.                 }
  21.         }
  22. }

  23. $ziDiuZhaoPin = new ZhaoPin('自丢','26','男','178');
  24. echo $ziDiuZhaoPin->ziDiu();
复制代码
PHP源码运行结果图:

构造方法__construct初始化并赋值实例化(PHP基础教程)

构造方法__construct初始化并赋值实例化(PHP基础教程)

香蕉 | 2019-8-20 04:27 | 显示全部楼层
自丢网真心不错,学习教程网。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

UID
1
贡献
387
丢币
38902
主题
4607
回帖
116
注册时间
2018-9-25
最后登录
2024-4-16