1.__constrtuct

基本用法

  1. <?php
  2. class test{
  3. function __construct(){
  4. }
  5. }
  6. $stu=new test();
  7. ?>

构造方法也叫构造函数,当对象实例化的时候执行

<?php

class show{
    private $name;
    private $big;
    public function __construct($name,$big){
        $this->name=$name;
        $this->big=$big;
}
    public function test(){
        echo "你的姓名:{$this->name}<br>";
        echo "你的年龄:{$this->big}<br>";
    }
}
$stu=new show('0ne',18);
$stu->test();


?>

image.png