Php 如何修复致命错误:Uncaught ArgumentCounter错误:函数Login::Login()的参数太少,传递了0?

Php 如何修复致命错误:Uncaught ArgumentCounter错误:函数Login::Login()的参数太少,传递了0?,php,Php,我试图将我的程序登录转换为OOP,但我得到ArgumentCountError。这是我的家庭作业,你能帮我吗 下面是我的php代码,带有类和登录函数,以及带有小php脚本的HTML登录页面 数据库连接是PDO 当我使用$login=new login启动我的php函数时; $login->login$email,$password,$type;我得到这个错误: 致命错误:Uncaught ArgumentCounter错误:函数Login::Login的参数太少,在第50行的C:\xampp\h

我试图将我的程序登录转换为OOP,但我得到ArgumentCountError。这是我的家庭作业,你能帮我吗

下面是我的php代码,带有类和登录函数,以及带有小php脚本的HTML登录页面

数据库连接是PDO

当我使用$login=new login启动我的php函数时; $login->login$email,$password,$type;我得到这个错误:

致命错误:Uncaught ArgumentCounter错误:函数Login::Login的参数太少,在第50行的C:\xampp\htdocs\public\u html\project OOP\include\Login.php中传递了0,而在C:\xampp\htdocs\public\u html\project OOP\include\include\Login.php50:Login->中正好传递了3{main}在第8行的C:\xampp\htdocs\public\u html\project OOP\include\login.php中抛出

我知道这里有很多错误,但我是个初学者

class Login{

   private $email;
   private $password;
   private $type;

   public function login($email,$password,$type){
            if(!empty($_POST['email']) && !empty($_POST['password'])&& !empty($_POST['type'])):
               switch ($_POST['type']) {
                  case 'Buyer':
                     $records = $conn->prepare('SELECT * FROM buyer WHERE email = :email');
                     break;
                  case 'Seller':
                     $records = $conn->prepare('SELECT * FROM seller WHERE email = :email');
                     break;

                  default:
                     break;
               }
               $_SESSION['type'] = $_POST['type'];

               $records->bindParam('email', $_POST['email']);
               $records->execute();
               $results = $records->fetch(PDO::FETCH_ASSOC);

               $message = '';

               if($results && count($results) > 0 && md5($_POST['password'], $results['password'])){
                  $_SESSION['user_id'] = $results['buyer_id'];
                  $_SESSION['name'] = $results['buyer_name'];
                  $_SESSION['email'] = $results['email'];
                  $_SESSION['password'] = $results['password'];
                  $_SESSION['phone'] = $results['phone'];
                  $_SESSION['description'] = $results['description'];
                  $_SESSION['status'] = $results['status'];


                  header("Location: index.php");
               } else {
                  $message = 'Sorry, those credentials do not match';
               }  
            endif;
         }
}
This is only for test
$email = "keno1@gmail.com";
$password = "123456";
$type = "Buyer";

$login = new Login;
$login->login($email,$password,$type);

My HTML code:

<?php

session_start();
if (  isset($_SESSION['user_id']) ){

    header("Location: index.php");
}

require 'database.php';



?>

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Login V1</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->  
    <link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
<!--===============================================================================================-->  
    <link rel="stylesheet" type="text/css" href="vendor/css-hamburgers/hamburgers.min.css">
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="css/util.css">
    <link rel="stylesheet" type="text/css" href="css/login.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <style type="text/css">
        body{ font: 14px sans-serif; }
        .wrapper{ width: 350px; padding: 20px; }
    </style>
<!--===============================================================================================-->
</head>
<body>
    <div class="limiter">
        <div class="container-login100">
            <div class="wrap-login100">
                <div class="login100-pic js-tilt" data-tilt>
                    <img src="images/img-01.png" alt="IMG">
                </div>

                <form class="login100-form validate-form" action="login.php" method="POST">
                    <span class="login100-form-title">
                        Member Login
                    </span>
                    <div class="wrap-input100 validate-input" data-validate = "Valid email is required: ex@abc.xyz">
                        <input class="input100" type="text" name="email" placeholder="Email">
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa fa-envelope" aria-hidden="true"></i>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input" data-validate = "Password is required">
                        <input class="input100" type="password" name="password" placeholder="Password">
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa fa-lock" aria-hidden="true"></i>
                        </span>
                    </div>
                    <select class="browser-default custom-select" name="type">
                        <option disabled="disabled" selected="selected">Profile type</option>
                        <option>Buyer</option>
                        <option>Seller</option>
                    </select>
                    <div class="container-login100-form-btn">
                        <button class="login100-form-btn" type="submit" name="submit">
                            Login
                        </button>
                    </div>

                    <div class="text-center p-t-12">
                        <span class="txt1">
                            Forgot
                        </span>
                        <a class="txt2" href="#">
                            email / Password?
                        </a>
                    </div>

                    <div class="text-center p-t-136">
                        <a class="txt2" href="register.php">
                            Create your Account
                            <i class="fa fa-long-arrow-right m-l-5" aria-hidden="true"></i>
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>  
<!--===============================================================================================-->  
    <script src="vendor/jquery/jquery-3.2.1.min.js"></script>
<!--===============================================================================================-->
    <script src="vendor/bootstrap/js/popper.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!--===============================================================================================-->
    <script src="vendor/select2/select2.min.js"></script>
<!--===============================================================================================-->
    <script src="vendor/tilt/tilt.jquery.min.js"></script>
    <script >
        $('.js-tilt').tilt({
            scale: 1.1
        })
    </script>
<!--===============================================================================================-->
    <script src="js/main.js"></script>

</body>
</html>
您的登录函数被解释为构造函数,因为它与类具有相同的名称。请参阅

由于错误报告设置,您不能看到弃用消息

不过,不赞成并不是问题所在,它最终会变成一个致命的错误,因为

$login = new Login;
调用login方法时不带参数,因为PHP将其视为构造函数


不过,您不需要_构造方法,因为该函数实际上不应该是构造函数。您只需更改类或方法的名称,就可以修复错误。

问题在于登录方法与类同名。它被解释为旧式构造函数。我相信问题在于t您正在使用旧版本的PHP。您应该尽快升级到最新版本。还要更改您的类或登录函数的名称,使它们不是相同的名称。