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;

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Fixing the CI_Pagination Constructor Deprecation Warning

You are seeing a strict error message in your PHP logs: Methods with the same name as their class will not be constructors in a future version of PHP. This warning points specifically to the libraries/Pagination.php file at line 27, identifying CI_Pagination as having a deprecated constructor.

This is not a bug; it is a consequence of PHP's evolving syntax standards. In older versions of PHP (pre-5.3), a class method named exactly like the class name automatically acted as the constructor. Modern PHP removed this "magic" behavior to enforce explicit constructor methods, aligning with standard object-oriented practices used in languages like Java or C#.

The error log confirms that CI_Pagination currently relies on this legacy behavior. If you are running PHP 7.2 or higher, this warning will eventually become a fatal error in future minor versions. To resolve this, you must explicitly define the __construct() method within the CI_Pagination class.

Implementing the Explicit Constructor

The fix is straightforward but requires modifying the file located at libraries/Pagination.php. You need to insert a new method definition before line 27 or replace the existing implicit behavior with an explicit one.

Here is how you should structure the updated class definition:

class CI_Pagination {
    // Define your properties here
    var $base_url           = ''; 
    var $total_rows         = ''; 
    var $per_page           = 10; 

    // The explicit constructor required by modern PHP standards
    public function __construct() {
        // You can initialize properties or run logic here if needed.
        // If your application relies on dependency injection, set variables here.
    }

    // Rest of your existing methods follow...
}

By adding public function __construct(), you signal to the PHP engine that you intend for this method to handle object initialization. This removes the ambiguity and silences the deprecation warning immediately.

Handling Version-Specific Behavior

It is important to note how this change affects your codebase depending on your PHP version. If you are running PHP 7.0 through 7.1, this specific warning might still appear as a notice rather than an error, but it serves as a critical heads-up for future compatibility. Moving to PHP 8.x makes this transition mandatory; the old implicit constructor behavior is completely gone.

If your CI_Pagination class was previously used with dependency injection frameworks (like Symfony or Laravel) that passed arguments to the constructor, you must ensure your new __construct() method accepts those parameters. For example:

public function __construct($per_page = 10) {
    $this->per_page = $per_page;
}

However, since the provided source material shows the class using var properties (a PHP 4 legacy feature) and lacking any parameter definitions, it is likely a standalone utility from an older CodeIgniter iteration. In this context, keeping the constructor empty is the safest approach to maintain backward compatibility while satisfying the new language requirements.

Migration Considerations for Legacy Codebases

The presence of var properties in the snippet suggests this is legacy code. While renaming var to public, private, or protected is a separate refactoring task, fixing the constructor warning is the immediate priority. If you choose to modernize the property visibility later, remember that explicit constructors allow for stricter type hinting and better initialization logic.

If you are using this pagination class within a larger application, verify that no external scripts expect the old implicit constructor behavior to trigger specific side effects upon instantiation. Once __construct() is defined, the object will initialize cleanly regardless of how it is instantiated:

$pager = new CI_Pagination(); // Works in all modern PHP versions

Addressing this warning now prevents potential application crashes when you upgrade your server's PHP version in the near future. The transition from implicit to explicit constructors is a standard step in maintaining robust, forward-compatible code.

Our network