Error: Strict Standards: Only variables should be passed by reference?

Error: Strict Standards: Only variables should be passed by reference?

我正在练习编码,并且正在根据我在 YouTube 上观看的视频制作登录系统。当我尝试注册一个帐户时一切正常,但唯一的问题是它给了我一个小错误说明:严格标准:只有变量应该在第 9 行的 /home/login-name/public_html/login/register.php 中通过引用传递。

Register.php

<?php
require 'database.php';

if(!empty($_POST['username']) && !empty($_POST['password'])):
    $sql = "INSERT INTO users (username, password) VALUES (:username, :password)";
    $stmt = $conn->prepare($sql);

    $stmt->bindParam(':username', $_POST['username']);
    $stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));

    if( $stmt->execute() ):
        die('Success');
    else:
        die('Fail');
    endif;
endif;
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Register</title>
        <meta charset=utf-8>
        <link href="../css/register.css" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
    </head>
    <body>
        <div class="header">
            <span class="header-logo"><a href="home">Abyssal Test</a></span>
        </div>
        <form action="register" method="POST">
            <input type="text" placeholder="Username" name="username">
            <input type="password" placeholder="Password" name="password">
            <input type="password" placeholder="Confirm Password" name="confirm_password">
            <input type="submit" name="register" value="Register">
            <span class="register-text">Already have an account? <a href="login">Login Here</a></span>
        </form>
    </body>
</html>

更改此行

$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));

$hash = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(':password', $hash);

正如函数 documentation 中所述,函数 "bindParam" 的第二个参数是一个变量引用,您尝试传递一个函数结果。所以你可以将函数的结果存储在一个变量中,然后将它传递给函数

$passwordHash=password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', $passwordHash);