0

При выполнении данного кода выходит ошибка(изображение) В функциях: public function signupUser() private function emptyInput() и в других проверяющих функциях.

Ошибка в классе-контроллере

signup.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="../assets/styles/authStyle.css">
    <title>Sign up</title>
</head>
<body>
    <div class="container">
        <section class="registration">
            <form action="../includes/signup.inc.php" method="POST">
                <h2>Регистрация</h2>
                <div>
                    <label for="nameId">Никнейм:</label>
                    <input type="text" name="name" id="nameId">
                </div>
                <div>
                    <label for="passwordId">Пароль:</label>
                    <input type="password" name="password" id="passwordId">
                </div>
                <div>
                    <label for="passwordId">Повторите пароль:</label>
                    <input type="password" name="confirmPassword" id="passwordId">
                </div>
                <div>
                    <label for="emailId">E-mail адрес:</label>
                    <input type="email" name="email" id="emailId">
                    <button type="submit">Подтвердить</button>
                </div>
            </form>
        </section>
    </div>
</body>
</html>

signup-controller.classes.php

<?php

class SignupController extends Signup { private $name; private $password; private $confirmPassword; private $email;

public function __construct($name, $password, $confirmPassword, $email)
{
    $this-&gt;$name = $name;
    $this-&gt;$password = $password;
    $this-&gt;$confirmPassword = $confirmPassword;
    $this-&gt;$email = $email;
}

public function signupUser() 
{
    if($this-&gt;emptyInput() == false) {
        //header(&quot;Location: ../auth/signup.php&quot;);
        //exit();
    }
    if($this-&gt;invalidName() == false) {
        header(&quot;Location: ../auth/signup.php&quot;);
        exit();
    }
    if($this-&gt;invalidEmail() == false) {
        header(&quot;Location: ../auth/signup.php&quot;);
        exit();
    }
    if($this-&gt;invalidPassowrd() == false) {
        header(&quot;Location: ../auth/signup.php&quot;);
        exit();
    }
    if($this-&gt;isUser() == false) {
        header(&quot;Location: ../auth/signup.php&quot;);
        exit();
    }

    $this-&gt;setUser($this-&gt;name, $this-&gt;password, $this-&gt;email);

}

private function emptyInput() 
{
    if(empty($this-&gt;name) || empty($this-&gt;password) || empty($this-&gt;confirmPassword) || empty($this-&gt;email)) {
        $result = false;
        throw new Exception(&quot;empty input&quot;);
    } else {$result = true;}
    return $result;
}

private function invalidName() {
    if(!preg_match('|^[A-Z0-9]+$|i', $this-&gt;name)) {
        $result = false; 
        throw new Exception(&quot;invalid name&quot;);
    }
    else {$result = true;}
    return $result;
}

private function invalidEmail() {
    if(!filter_var($this-&gt;email, FILTER_VALIDATE_EMAIL)) {
        $result = false;
        throw new Exception(&quot;invalid email&quot;);
    }
    else {$result = true;}
    return $result;
}

private function invalidPassowrd() {
    if($this-&gt;password !== $this-&gt;confirmPassword) {
        $result = false;
        throw new Exception(&quot;not match&quot;);
    } else if (strlen($this-&gt;password) &lt; 8) {
        throw new Exception(&quot;password is too short, need 8 symbols&quot;);
        $result = false;
    } else if (strlen($this-&gt;password) &gt; 256) {
        throw new Exception(&quot;password is too long, need less then 256 symbols&quot;);
        $result = false;
    } else {$result = true;}
    return $result;
}

private function isUser() {
    if (!$this-&gt;checkUser($this-&gt;name, $this-&gt;email)) {
        $result = false;
        throw new Exception(&quot;User had already been created&quot;);
    } 
    else {$result = true;}
    return $result;
}

}

void
  • 1
  • ну и что тут не ясного? ты сам же выкидываешь эксепшн при пустом вводе – Алексей Шиманский May 05 '22 at 17:41
  • Можешь пожалуйста пояснить подробнее? Я только обучаюсь. Я ввёл все поля в форме, но exception по условию должен выкидываться когда result должен быть ложным. У меня exception появляется всё время, даже если все условия выполнены. – void May 05 '22 at 17:45
  • 1
    отладка тебе в помощь ↑↑↑ ты будешь часто в процессе работы ею пользоваться... смотри что где и как у тебя происходит, заполняется и т.д. на каждом шаге что у тебя имеется – Алексей Шиманский May 05 '22 at 17:46

1 Answers1

0

В конструкторе по всей видимости эти строки:

        $this->$name = $name;
        $this->$password = $password;
        $this->$confirmPassword = $confirmPassword;
        $this->$email = $email;

Нужно заменить на эти:

        $this->name = $name;
        $this->password = $password;
        $this->confirmPassword = $confirmPassword;
        $this->email = $email;