How to fix Fatal error: Uncaught ArgumentCountError: Too few arguments to function Login::login(), 0 passed?

Kenan Babacic

I'm trying to convert my procedural login to OOP but I get ArgumentCountError. This is a project for my homework, can you help me?

Down below is my php code with class and login function and HTML Login page with small php script.

DB Connection is PDO.

When i going to istance my php function with "$login = new Login; $login->login($email,$password,$type);" i get this error:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function Login::login(), 0 passed in C:\xampp\htdocs\public_html\project OOP\include\login.php on line 50 and exactly 3 expected in C:\xampp\htdocs\public_html\project OOP\include\login.php:8 Stack trace: #0 C:\xampp\htdocs\public_html\project OOP\include\login.php(50): Login->login() #1 {main} thrown in C:\xampp\htdocs\public_html\project OOP\include\login.php on line 8.

I know that there are a lot of mistakes here, but I'm a beginner.

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 = "[email protected]";
$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: [email protected]">
                        <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>
Don't Panic

Your login function is being interpreted as a constructor because it has the same name as the class. (See PHP 4 Style Constructors.)

You must not be seeing the deprecation message because of your error reporting settings.

The deprecation isn't the problem, though. It ends up turning into a fatal error because

$login = new Login;

calls the login method with no arguments, since PHP treats it like a constructor.

You don't need a __construct() method though, because that function isn't actually supposed to be a constructor. You can just change the name of the class or the method, that should fix the error.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function sendRegistrationErrorNotification()

分類Dev

Too few arguments in function

分類Dev

Too few arguments to pass to a function in Laravel

分類Dev

Laravel - Type error: Too few arguments?

分類Dev

login to postgres as another user gives FATAL error

分類Dev

Laravel Policy (Too few arguments to function App\Policy)

分類Dev

How to capture the names of multiple arguments (...) passed to a function?

分類Dev

Error: too few arguments, must supply command line package specs or --file

分類Dev

Php Login Error - unsuccessful login

分類Dev

Using Jest, how to check arguments passed in a mocked function

分類Dev

Fatal error: Uncaught Error: Call to undefined function ereg_replace() PHP 7

分類Dev

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

分類Dev

Implementing Oauth2 login, Fatal error: Class 'Google_Service' not found

分類Dev

SQLite insert function/method too many parameter arguments, how to refactor?

分類Dev

vue-router — Uncaught (in promise) Error: Redirected from "/login" to "/" via a navigation guard

分類Dev

Laravel - Login sql error

分類Dev

Login error in C#

分類Dev

Insecure login error while login with facebook php

分類Dev

'Uncaught SyntaxError:Unexpected token <' on Login Form

分類Dev

Fatal error: Uncaught phpmailerException: SMTP connect() failed

分類Dev

Passing too few arguments to printf for the format specifier — is it undefined behavior?

分類Dev

Why its saying 0 arguments passed

分類Dev

Fix Synergy so it works on Login/Locked screen

分類Dev

Fix plugin Fatal error in EXEC-php

分類Dev

How to login in feature specs

分類Dev

How to create login configuration

分類Dev

How to fix "Recoverable fatal error: Object of class Closure could not be converted to string in..."

分類Dev

How to fix: fatal error: openssl/opensslv.h: No such file or directory in RedHat 7

分類Dev

Login through sqlite giving error

Related 関連記事

  1. 1

    PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function sendRegistrationErrorNotification()

  2. 2

    Too few arguments in function

  3. 3

    Too few arguments to pass to a function in Laravel

  4. 4

    Laravel - Type error: Too few arguments?

  5. 5

    login to postgres as another user gives FATAL error

  6. 6

    Laravel Policy (Too few arguments to function App\Policy)

  7. 7

    How to capture the names of multiple arguments (...) passed to a function?

  8. 8

    Error: too few arguments, must supply command line package specs or --file

  9. 9

    Php Login Error - unsuccessful login

  10. 10

    Using Jest, how to check arguments passed in a mocked function

  11. 11

    Fatal error: Uncaught Error: Call to undefined function ereg_replace() PHP 7

  12. 12

    How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

  13. 13

    Implementing Oauth2 login, Fatal error: Class 'Google_Service' not found

  14. 14

    SQLite insert function/method too many parameter arguments, how to refactor?

  15. 15

    vue-router — Uncaught (in promise) Error: Redirected from "/login" to "/" via a navigation guard

  16. 16

    Laravel - Login sql error

  17. 17

    Login error in C#

  18. 18

    Insecure login error while login with facebook php

  19. 19

    'Uncaught SyntaxError:Unexpected token <' on Login Form

  20. 20

    Fatal error: Uncaught phpmailerException: SMTP connect() failed

  21. 21

    Passing too few arguments to printf for the format specifier — is it undefined behavior?

  22. 22

    Why its saying 0 arguments passed

  23. 23

    Fix Synergy so it works on Login/Locked screen

  24. 24

    Fix plugin Fatal error in EXEC-php

  25. 25

    How to login in feature specs

  26. 26

    How to create login configuration

  27. 27

    How to fix "Recoverable fatal error: Object of class Closure could not be converted to string in..."

  28. 28

    How to fix: fatal error: openssl/opensslv.h: No such file or directory in RedHat 7

  29. 29

    Login through sqlite giving error

ホットタグ

アーカイブ