“Passing null to parameter #1 ($string) of type string is deprecated” in WordPress
Short answer
It’s a deprecation notice from PHP 8.1 and later: a plugin or theme gives one of PHP’s own functions, such as strlen() or trim(), the value null where it expects text. The code keeps working; on PHP 8.1 to 8.5 it only adds this message. The accepted plan turns it into an error in PHP 9.0. A check that reads code can’t find it in advance, because the same line is fine or not depending on the value while the site runs: you find it in your error log, where the message names the plugin’s file and line.
The message, exactly
This is the real output of a small search plugin on PHP 8.0 and 8.1. The address has no search term, so the plugin’s variable holds null:
wp-content/plugins/search-box/search-box.php
<?php
$search = filter_input(INPUT_GET, 'q'); // null when the address has no ?q=
$length = strlen($search);
$trimmed = trim($search);
$words = str_replace('-', ' ', $search);
echo "Length: $length, trimmed: [$trimmed], words: [$words]\n";
Length: 0, trimmed: [], words: []Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 4
Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 5
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 6
Length: 0, trimmed: [], words: []The same code on PHP 8.2, 8.3, 8.4 and 8.5
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 4
Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 5
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 6
Length: 0, trimmed: [], words: []Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 4
Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 5
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 6
Length: 0, trimmed: [], words: []Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 4
Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 5
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 6
Length: 0, trimmed: [], words: []Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 4
Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 5
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/html/wp-content/plugins/search-box/search-box.php on line 6
Length: 0, trimmed: [], words: []
PHP 8.0 says nothing; PHP 8.1 and every later version add one notice per call. The function name and the parameter change (#1 ($string) for strlen() and trim(), #3 ($subject) of type array|string for str_replace()); the rest of the sentence is the same, so searching your log for “Passing null to parameter” finds all of them.
What it means
PHP’s own functions used to accept null where they expect text or a number, and quietly treated it as an empty value. PHP 8.1 deprecated that: “Scalar types for built-in functions are nullable by default. This behaviour is deprecated to align with the behaviour of user-defined functions, where scalar types need to be marked as nullable explicitly.” (php.net)
The result stays the same: in the example, the length is still 0 and the texts are still empty.
Is it urgent?
No. It is a notice, not an error, and the code does what it did before. It will need a fix at some point: the proposal behind it, accepted by PHP’s developers, says that “in PHP >= 9.0 a TypeError is thrown” (PHP RFC). The versions released so far, up to 8.5, only show the notice.
Why a code check can’t find it
Whether a line gets this notice depends on the value it works with while the site runs, not on how the code is written. The same function, on the same line, is fine once and gets the notice once:
wp-content/plugins/search-box/includes/helpers.php
<?php
function title_length($title) {
return strlen($title);
}
echo title_length('Hello'), "\n";
echo title_length(null), "\n";
5
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wp-content/plugins/search-box/includes/helpers.php on line 3
0A check that reads code sees strlen($title), not what $title will hold on your site. CompatNav doesn’t report this notice for that reason: its scan of the examples on this page finds nothing. Your error log is where it shows up.
Find it in your log
- Open your PHP error log: in your hosting control panel (often under “Logs” or “Error log”), or ask your host where it is. If WordPress writes its own log, it’s
wp-content/debug.logor the file set inWP_DEBUG_LOG. - Search for “Passing null to parameter”. Each line names the PHP function, then the file and line.
- Read the path: the folder after
wp-content/plugins/orwp-content/themes/is the plugin or theme. - Update it (Dashboard → Updates); its developer may already have fixed it.
- Already on the latest version? Send the full line to its developer.
No log yet? The WordPress settings that write one, and how to keep messages off your pages, are in Deprecation notice vs fatal error.
New to wp-config.php? How to edit it safely
- Make a copy first. Download the file, or duplicate it, so you can put it back if something goes wrong.
- Open the file. In your hosting control panel, open the File Manager and go to your WordPress folder (often called
public_html).wp-config.phpis usually there, next to thewp-adminandwp-contentfolders. You can also use an FTP program with the FTP details your host gives you. - Find the right place. Add new lines above the line
/* That's all, stop editing! Happy publishing. */(on older sites it ends with “Happy blogging”). If a line with the same name is already there, for exampledefine( 'WP_DEBUG', false );, change that line instead of adding a second one. - Save, then reload your site. If it shows an error, put your copy back.
Not comfortable doing this? Ask your host’s support to make the change; it’s a routine request.
Another notice you may meet, new in PHP 8.2, is explained in “Creation of dynamic property … is deprecated”.
Key takeaways
- It’s a deprecation notice from PHP 8.1 and later:
nullgiven to a PHP function that expects text. The code keeps working. - The function name and the parameter change from message to message (
#1 ($string),#3 ($subject)…); the rest of the sentence is always the same. - No code check can find it before the upgrade: whether the value is
nullis only known while the site runs. Look for it in your error log. - The file path in the message shows which plugin or theme it comes from; update it or send the message to its developer.
- The accepted plan makes it a TypeError in PHP 9.0; the versions released so far, up to 8.5, only show the notice.
Frequently asked questions
Can I ignore it?
For now, yes: the site works the same with or without the message. Pass it on to the plugin’s developer anyway, because the accepted plan for PHP 9.0 turns it into an error.
Why can’t a check find it before the upgrade?
Because the code is only wrong with some values. strlen($title) is fine when $title holds text and gets the notice when it holds null, and which one happens depends on your data, your settings and what visitors send. A check that reads code sees the line, not the value.
Why do I see it only on some pages?
PHP writes the notice only when that line runs with null: on the page that uses the plugin’s feature, with a setting left empty, or when a form field or address parameter is missing.
Do I need to edit the plugin?
No. Changes to a plugin’s files are lost with its next update. Update the plugin, or send the full message to its developer; the fix is usually one line.
Check your own site before you upgrade
CompatNav is a free WordPress plugin. It reads the code of your plugins and themes on your own server and tells you, in plain words, what will break and what will only show notices on the PHP version you choose. It never changes your code. It can’t see problems that only appear while code runs with real data, so a quick check of your site after the upgrade still matters.
Sources
- php.net: Deprecated features in PHP 8.1.x
- PHP RFC: Deprecate passing null to non-nullable arguments of internal functions (accepted, implemented in PHP 8.1)
- developer.wordpress.org: Debugging in WordPress
About the code examples: each output is the real output of the code shown, run with the official PHP builds, without a php.ini, with all errors reported and displayed. Only the file path was replaced by a neutral server path.