我遇到错误,但是我不知道为什么?

时间:2020-06-25 17:54:53

标签: php class

<?php
class User {

    public $id;
    public $first_name;
    public $last_name;
    public $age;
  
    public function __construct($id, $first_name, $last_name, $age)
    {
        $this->id = $id;
        $this->first_name = $first_name;
        $this->last_name = $last_name;
        $this->age = $age;
    }
    
    public function name()
    {
        echo "ID: <br />" .$this->id. " Ime : <br />" .$this->first_name. " Prezime : <br />" .$this->first_name;
    }
    
    public  function age()
    {
        if ($this->age >=18) {
            echo "Punoljetan(18+)";
        }
        else {
            echo "Maloljetan (18-)";
        }
    }

    $klijent = new User(1,'Vladmir','Bozic', 12);
    $klijent -> name();
    $klijent -> age();
    echo "<br />";
    echo "<br />";
    echo "<br />";
    echo "<br />";
    $klijent = new User(2,'Nevenko','Markovic', 25);
    $klijent -> name();
    $klijent -> age();
?>

/ *解析错误:语法错误,第25行的C:\ xampp \ htdocs \ klasa.php中出现意外的'$ klijent'(T_VARIABLE),期望函数(T_FUNCTION)或const(T_CONST)

0 个答案:

没有答案