:::

25. construct

The syntax:

public function __construct($prop1, $prop2) {
  $this->prop1 = $prop1;
  $this->prop2 = $prop2;
}

<?php
  class Person {
    public $isAlive = true;
    public $firstname;
    public $lastname;
    public $age;
    public function __construct($firstname,$lastname,$age){
        $this->firstname = $firstname;
        $this->lastname = $lastname;
        $this->age = $age;
  }
    
  }
  $teacher = new Person("boring", "12345", 12345);
  $student = new Person("boring", "12345", 12345);
  echo $teacher->isAlive;
  echo $student->age;
?><!-- Your code here -->
      </p>


:::

語系選擇