Resolving the PHP Deprecated: create_function() Error in Broken Link Checker
Content
If you're using the Broken Link Checker plugin on a modern PHP version (7.2 or higher), you've likely encountered a persistent and spammy error in your server logs. This guide explains the cause of this error and provides the most effective solutions to resolve it.
The Problem: Deprecated PHP Function
The error message is consistent across reports:
PHP Deprecated: Function create_function() is deprecated in /wp-content/plugins/broken-link-checker/modules/checkers/http.php on line 147
This occurs because the PHP function create_function() was officially deprecated starting in PHP 7.2 and completely removed in later versions (like PHP 8.0). The Broken Link Checker plugin was using this outdated function, causing modern PHP installations to log a deprecated warning every time the function was called. This can quickly fill up debug logs and cause unnecessary clutter.
Why This Happened
The 'Broken Link Checker' plugin went through a period of limited maintenance. During this time, PHP evolved and removed older, less secure functions like create_function(). The plugin's code was not immediately updated to use modern PHP alternatives, leading to this widespread issue. As evidenced in the support threads, users began reporting this problem as early as 2018 when they upgraded to PHP 7.2.
Recommended Solutions
Solution 1: Update the Plugin (Most Recommended)
The simplest and safest solution is to ensure you are running the latest version of the Broken Link Checker plugin. The WPMU DEV team eventually took over maintenance and addressed this specific issue in a later update. Updating the plugin is the most secure and sustainable fix, as it will include all other patches and security improvements released since the older versions.
- Go to your WordPress dashboard.
- Navigate to Plugins → Installed Plugins.
- Find "Broken Link Checker" and check if an update is available.
- Always create a full backup of your site before performing updates.
Solution 2: Apply a Manual Code Patch (If Updating is Not an Option)
Warning: This involves editing plugin source code. Only proceed if you are comfortable with this process. Always create a complete backup of your site first, as editing plugins directly can cause issues if done incorrectly.
If you cannot update the plugin, the community has identified a direct code replacement. The deprecated code is found in the file wp-content/plugins/broken-link-checker/modules/checkers/http.php.
Original Code (Line ~147):
return preg_replace_callback(
'|[^a-z0-9+-/\#:.,;=?!&%@()$|*~_]|i',
create_function('$str','return rawurlencode($str[0]);'),
$url
);
Patched Code:
return preg_replace_callback(
'|[^a-z0-9+-/\#:.,;=?!&%@()$|*~_]|i',
function ($str) {
return rawurlencode($str[0]);
},
$url
);
This change replaces the deprecated create_function() call with a modern anonymous function, which is the recommended PHP standard. After making this change, the deprecation notice should cease.
Conclusion
The create_function() deprecation notice is a known legacy issue with older versions of the Broken Link Checker plugin. The most efficient and secure way to resolve it is to update the plugin to its latest version. If that's not immediately possible, the manual code patch provides a effective temporary workaround. For further independent discussion, many community forums have threads detailing this specific problem and its solutions.
Related Support Threads Support
-
Php Logfile error: create_function() is deprecatedhttps://wordpress.org/support/topic/php-logfile-error-create_function-is-deprecated/
-
Error create_function()https://wordpress.org/support/topic/error-create_function/
-
PHP Deprecatedhttps://wordpress.org/support/topic/php-deprecated-8/
-
Deprecated: Function create_function()https://wordpress.org/support/topic/deprecated-function-create_function/
-
php 7.2 Deprecated functionhttps://wordpress.org/support/topic/php-7-2-deprecated-function/
-
PHP 7.2 Issue with create_functionhttps://wordpress.org/support/topic/php-7-2-issue-with-create_function/
-
Deprecated function in new PHP 7.2https://wordpress.org/support/topic/deprecated-function-in-new-php-7-2/
-
Deprecated Function for PHP 7.xhttps://wordpress.org/support/topic/deprecated-function-for-php-7-x/
-
PHP Warning: Deprecated functionhttps://wordpress.org/support/topic/php-warning-deprecated-function/
-
PHP Deprecated: Function create_function()https://wordpress.org/support/topic/php-deprecated-function-create_function-2/
-
This alert been apearing eons…https://wordpress.org/support/topic/this-alert-been-apearing-eons/
-
PHP error Noticehttps://wordpress.org/support/topic/php-error-notice-7/
-
PHP Deprecated: Function create_function()https://wordpress.org/support/topic/php-deprecated-function-create_function-3/
-
Deprecated jQuery codehttps://wordpress.org/support/topic/deprecated-jquery-code-29/
-
Deprecated functionhttps://wordpress.org/support/topic/deprecated-function-35/