【问题标题】:PHP Deprecated: Methods with the same name password hash [duplicate]不推荐使用PHP:具有相同名称密码哈希的方法[重复]
【发布时间】:2017-08-07 15:45:52
【问题描述】:

错误密码散列线 1 类密码散列

不推荐使用 PHP:与其类同名的方法在 PHP 的未来版本中将不再是构造函数; PasswordHash 有一个不推荐使用的构造函数 如何修复错误? 我的数据库 7.1

class PasswordHash {
var $itoa64;
var $iteration_count_log2;
var $portable_hashes;
var $random_state;
var $hash_method; // do not modify directly, use set_hash_method instead.

function PasswordHash($iteration_count_log2 = 9, $portable_hashes = false, $hash_method = null, $full_compat = true)
{
    $this->portable_hashes = $portable_hashes;
    $this->full_compat = $full_compat;

    if ($this->set_hash_method($hash_method)===false){
        return false;
    }
    $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
        $iteration_count_log2 = 8;
    $this->iteration_count_log2 = $iteration_count_log2;
    $this->random_state = microtime();
    if (function_exists('getmypid'))
        $this->random_state .= getmypid();

    return $this;
}

【问题讨论】:

  • 在 php 类构造函数中与类名不同,只需将 function PasswordHash 替换为 public function __construct
  • 伙计们,让我们投票结束这个问题。它太简单了,垃圾和太宽泛
  • PHP 确实有一个相当全面的在线手册,你知道的。我建议您阅读它以了解此类内容。

标签: php


【解决方案1】:

好吧,我不知道您使用的是哪个版本的 PHP,但警告消息告诉您应该停止使用与类同名的构造函数,而改用 __construct

class PasswordHash {
var $itoa64;
var $iteration_count_log2;
var $portable_hashes;
var $random_state;
var $hash_method; // do not modify directly, use set_hash_method instead.

function __construct($iteration_count_log2 = 9, $portable_hashes = false, 
    $hash_method = null, $full_compat = true) {
...

【讨论】:

    【解决方案2】:

    在 PHP 4 中,构造函数与类同名。自 PHP7 以来,它不是一个选项。 您应该使用名称 PasswordHash 重命名方法。 而且构造函数也不返回值。

    【讨论】:

    • 抱歉打断了德米特,但你必须同意有很多这样的问题有答案,而且太简单了——不是你的水平来回答那些懒得从简单的英文句子理解的人:Methods with the same name as their class will not be constructors in a future version of PHP只需去阅读php.net/manual/en/language.oop5.decon.php 了解类构造函数
    猜你喜欢
    • 2016-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 2012-02-24
    • 2020-03-25
    相关资源
    最近更新 更多