Uncaught ErrorException: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated codeigniter

Uncaught ErrorException: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated codeigniter

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

Stefan Bogdanescu

Founder & Senior Architect

Fixing strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in CodeIgniter 4

If you are running CodeIgniter 4.1.5 on PHP 8.1 or higher, you might encounter an ErrorException during form submissions that looks like this:

Uncaught ErrorException: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in ...system/Validation/FormatRules.php:253

This error occurs because PHP 8.1 introduced strict deprecation warnings for passing null to functions expecting a string. The stack trace points to CodeIgniter\Validation\FormatRules::valid_ip(), which is being called from $this->request->getIPAddress().

Why This Happens

The root cause is how CodeIgniter 4 handles IP address validation within its core FormatRules class. When you define a validation rule like 'valid_emails' or, in specific contexts, IP-related checks, the framework attempts to normalize the input string by running it through strtolower().

In PHP versions prior to 8.1, passing null to these functions would simply result in an empty string or no error. However, PHP 8.1 enforces stricter type safety. If the underlying data being processed is null, the function throws a deprecation error. In your specific case, this is likely triggered when the request object does not have a valid IP address set, or when the validation logic internally attempts to cast a missing value to a string without first checking for nullability.

Looking at your controller, you are validating user registration data (name, email, password). You are not explicitly validating an IP address field in your request array. However, CodeIgniter's internal validation engine sometimes invokes helper methods like valid_ip during the initialization or normalization of requests, specifically when checking headers or remote addresses if they are loosely typed or missing.

The Fix: Handling Null in Validation Rules

The most robust solution is to ensure that any string passed to validation rules can handle null values gracefully, or to adjust how you access request data if the framework's internal assumptions about IP presence are too strict for your environment.

However, since this error originates from system/Validation/FormatRules.php, changing your controller logic alone might not stop the framework from calling that method internally. The cleanest approach in a CodeIgniter 4 application is to patch the specific line causing the deprecation or adjust the PHP error reporting configuration if you are in a development environment and want to suppress this specific noise while maintaining strict typing for critical errors.

If you prefer to fix the logic rather than suppress the error, check your .env file. You have database.default.DBDriver = MySQLi. Ensure that your database connection is actually established before validation runs if the validation depends on DB checks (though valid_ip is usually local). The issue here is almost certainly unrelated to your database configuration shown in the .env snippet, but rather the interaction between PHP 8.1's type system and CI4's legacy string handling.

Recommended Implementation Strategy

Since you are on PHP 8.1, ignoring deprecation warnings can lead to fatal errors in future versions (PHP 8.2+). You have three options:

  1. Suppress the specific error: Add a @ suppressor or adjust your php.ini if this is purely noise in development.

    ; In php.ini for local development only
    display_startup_errors = On
    display_errors = On
    error_reporting = E_ALL & ~E_DEPRECATED
    
  2. Override the FormatRules Trait: You can create a custom trait that overrides valid_ip to handle nulls before passing them to strtolower. This requires modifying your system files, which is generally discouraged unless you are comfortable with version control hygiene for framework patches.

  3. Update CodeIgniter 4: If you have not done so, upgrading from 4.1.5 to a newer patch version (e.g., 4.x LTS) might resolve this if the maintainers have addressed the null-handling in FormatRules. The error persists because the framework assumes an IP string exists when one isn't guaranteed.

Conclusion

The error is a direct consequence of PHP 8.1's stricter type checking colliding with CodeIgniter 4's internal validation logic. Since your form helper and controller logic appear syntactically correct, the fix lies in how the framework handles missing data types internally. Adjusting your PHP error reporting for development or upgrading your CodeIgniter version are the most practical immediate steps to restore functionality without modifying core system files.

Our network