0
<?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();
?>

/* Parse error: syntax error, unexpected '$klijent' (T_VARIABLE), expecting function (T_FUNCTION) or const (T_CONST) in C:\xampp\htdocs\klasa.php on line 25

brombeer
  • 8,716
  • 5
  • 21
  • 27
  • 4
    Missing a closing `}` for your class. – brombeer Jun 25 '20 at 17:57
  • 4
    You've not closed the class definition before declaring your var. Proper indentation would help you spot this more quickly. – Mitya Jun 25 '20 at 17:58
  • 1
    I formatted the code for you - clearly spottable now – brombeer Jun 25 '20 at 17:59
  • Yeah but i still got an error //*Parse error: syntax error, unexpected '$klijent' (T_VARIABLE), expecting function (T_FUNCTION) or const (T_CONST) in C:\xampp\htdocs\klasa.php on line 32 – Đorđe Đukić Jun 25 '20 at 18:05
  • 1
    You will not be getting that error if you add the closing `}` for your class (right before `$klijent = new User(1,'Vladmir','Bozic', 12);` – brombeer Jun 26 '20 at 04:28

0 Answers0