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

fix methods with the same name as their class will not be constructors in a future version of php
a php error was encountered severity: 8192
use of deprecated php4 style class constructor is not supported since php 7
constructor in php7
php 7.3 constructor
php deprecated
php class constructor with parameters
php class init() method

Severity: 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

Filename: libraries/Pagination.php

Line Number: 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';

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

public function __construct(){
}

And the error will disappear.

Severity: 8192 Message: Methods with the same name as , Severity: 8192 Message: Methods with the same name as their class will not be constructors in a future version of PHP; Template has a deprecated constructor. Severity: 8192 Message: Methods with the same name as their class will not be constructors in a future version of PHP; Template has a deprecated constructor This comment has been minimized.

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.

So here you have to user

class CI_Pagination {
 public function  __construct() {
 }
}

instead of

class CI_Pagination {
 public function CI_Pagination () {
 }
}

[Php7] Methods with the same name as their class will not be , Error for Php7: Message: Methods with the same name as their class will not be constructors in a future version of PHP; Usertracking has a  Severity: 8192 Message: Methods with the same name as their class will not be constructors in a future version of PHP; MarkdownExtra_Parser has a deprecated constructor Filename: helpers/markdown_helper.php

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

Deprecated features in PHP 7.0.x - Manual, Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; foo has a deprecated constructor in example.php on  There seems to be issues with methods having same name as their class for Markdown_Parser and Modules.php. As you already know it's something that will be deprecated.

For 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

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

to

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

remove 'browser'

Procog, A PHP Error was encountered. Severity: 8192. Message: Methods with the same name as their class will not be constructors in a future version of PHP;  Severity: 8192. Message: Methods with the same name as their class will not be constructors in a future version of PHP; CI_DB_driver has a deprecated constructor

Loader.php 414 line, I have removed Ampersent.

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

to

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

It works fine in php5.x.

A PHP Error was encountered, Severity: 8192. Message: Methods with the same name as their class will not be constructors in a future version of PHP; CI_Hooks has a deprecated constructor. PHP7 will output a deprecation message when a class with a PHP4-style constructor is loaded (not necessarily used): ​. PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; SubClass has a deprecated constructor in /path/to/file.php on line 15​.

Deprecated: Methods with the same name as their class will not be , A PHP Error was encountered. Severity: 8192. Message: Methods with the same name as their class will not be constructors in a future version of PHP; CI_Hooks has a deprecated constructor. Filename: libraries/Hooks.php. Line Number: 30  Young Hydro entrepreneur Sushil Pokharel has been appointed as the president of Rotary Club of Kathmandu North-East for Rota year 2019/2020. Pokhreal as a promoter of 57.3 MW Myagdi Khola Hydro Power project in Myagdi District, it has been already

dapperQ, Severity: 8192. Message: Methods with the same name as their class will not be constructors in a future version of PHP; CI_Hooks has a deprecated constructor. NuSphere announced it is partnering with the MySQL open source database community to develop a row-level locking capability for the MySQL database. Code-named Gemini, this project will be part of MySQL Version 4, targeted for release in the spring of 2001.

Error on installation, Severity: 8192. Message: Methods with the same name as their class will not be constructors in a future version of PHP; Admin_install has a deprecated constructor. Filename: controllers/Admin_install.php. Line Number: 14. A PHP Error was  Severity: 8192. Message: Methods with the same name as their class will not be constructors in a future version of PHP; Filesystem_Cache_System has a deprecated constructor. Filename: _common/waterfall_cache.php. Line Number: 440

Comments
  • And your question is?
  • What version of CodeIgniter?
  • The error is pretty self-explanatory. Your old code is not following what is now considered best practice and if you don't update it it will no longer work in future versions of PHP. In this case it's because a class constructor should be called __construct() instead of whatever the class name is.
  • Can you please improve this explanation and provide some sample source code? Otherwise, this post does not seem to provide a quality answer to the question.
  • How is this related to the question which asks for differences in the syntax of constructors?