严重性:8192 消息:与它们的类同名的方法在 PHP 的未来版本中将不再是构造函数;

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40320062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:09:04  来源:igfitidea点击:

Severity: 8192 Message: Methods with the same name as their class will not be constructors in a future version of PHP;

phpcodeignitercodeigniter-2codeigniter-3

提问by Andra Maullana

Severity: 8192

严重性:8192

Message: Methods with the same name as their class will not be constructors in a future version of PHP; CI_Pagination has a deprecated constructor

消息:与它们的类同名的方法在 PHP 的未来版本中将不再是构造函数;CI_Pagination 有一个不推荐使用的构造函数

Filename: libraries/Pagination.php

文件名:libraries/Pagination.php

Line Number: 27

行号:27

class CI_Pagination {

    var $base_url           = ''; // The page we are linking to
    var $total_rows         = ''; // Total number of items (database results)
    var $per_page           = 10; // Max number of items you want shown per page
    var $num_links          =  2; // Number of "digit" links to show before/after the currently viewed page
    var $cur_page           =  0; // The current page being viewed
    var $first_link         = '‹ First';
    var $next_link          = '>';
    var $prev_link          = '<';
    var $last_link          = 'Last ›';
    var $uri_segment        = 3;
    var $full_tag_open      = '';
    var $full_tag_close     = '';
    var $first_tag_open     = '';
    var $first_tag_close    = ' ';
    var $last_tag_open      = ' ';
    var $last_tag_close     = '';
    var $cur_tag_open       = ' ';
    var $cur_tag_close      = '';
    var $next_tag_open      = ' ';
    var $next_tag_close     = ' ';
    var $prev_tag_open      = ' ';
    var $prev_tag_close     = '';
    var $num_tag_open       = ' ';
    var $num_tag_close      = '';
    var $page_query_string  = FALSE;
    var $query_string_segment = 'per_page';

回答by Someone Special

Previously we used to declare class constructor using the class name itself

以前我们使用类名本身来声明类构造函数

Class A
{

public function a(){
}
}

Now you need to change a() to construct, like this

现在你需要改变 a() 来构造,像这样

public function __construct(){
}

And the error will disappear.

错误将消失。

回答by rakesh vadhel

It is occur with new version of php ,So if you want to remove this error please use _construct() instead of same class name function.

它发生在新版本的 php 中,所以如果你想消除这个错误,请使用 _construct() 而不是相同的类名函数。

So here you have to user

所以在这里你必须用户

class CI_Pagination {
 public function  __construct() {
 }
}

instead of

代替

class CI_Pagination {
 public function CI_Pagination () {
 }
}

回答by Manish

class NewClass{
}
function __construct(){
} //is used inplace of a function named NewClass for constructor

change function name having same name as class to __construct and it will work. Faced such problem in google maps api v3

将与类同名的函数名更改为 __construct ,它将起作用。在 google maps api v3 中遇到这样的问题

回答by Faridul Khan

For Codeigniter

对于 Codeigniter

First Step:

第一步:

class MyClass{
 function __construct(){
    // copy your old constructor function code here
 }
}

Next Step(if first step not working): Open application\config\autoload.php and edit

下一步(如果第一步不起作用):打开 application\config\autoload.php 并编辑

$autoload['libraries'] = array('database', 'session','browser');

to

$autoload['libraries'] = array('database', 'session');

remove 'browser'

删除“浏览器”

回答by madan chunchu

Loader.php 414 line, I have removed Ampersent.

Loader.php 414 行,我已经删除了 Ampersent。

$CI->dbutil =& new $class();

to

$CI->dbutil = new $class();

It works fine in php5.x.

它在 php5.x 中运行良好。