Deprecated function: addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Database\Connection->escapeLike()

Created on 28 October 2022, about 2 years ago
Updated 23 February 2023, over 1 year ago

Problem/Motivation

Following error is thrown while upgrading from Drupal 8.7 to Drupal 9.4:

Deprecated function: addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Database\Connection->escapeLike() (line 1525 of core/lib/Drupal/Core/Database/Connection.php).

Drupal\Core\Database\Connection->escapeLike(NULL) (Line: 420)
Drupal\Core\Database\Query\Select->escapeLike(NULL) (Line: 118)
Drupal\Core\Entity\Query\Sql\Condition::translateCondition(Array, Object, ) (Line: 63)
Drupal\Core\Entity\Query\Sql\Condition->compile(Object) (Line: 176)
Drupal\Core\Entity\Query\Sql\Query->compile() (Line: 80)
Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 81)
Drupal\dspace_harvester\Controller\HarvesterController->harvest() (Line: 31)
dspace_harvester_cron(Object)
call_user_func('dspace_harvester_cron', Object) (Line: 325)
Drupal\ultimate_cron\Entity\CronJob->invokeCallback() (Line: 471)
Drupal\ultimate_cron\Entity\CronJob->run(Object) (Line: 24)
Drupal\ultimate_cron\Controller\JobController->runCronJob(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 21)

Steps to reproduce

Proposed resolution

I have already tried the steps mentioned in the below url but, still the error occurs:

https://www.drupal.org/project/paragraphs/issues/3253545 ā†’

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

šŸ’¬ Support request
Status

Closed: outdated

Version

9.5

Component
DatabaseĀ  ā†’

Last updated 2 days ago

  • Maintained by
  • šŸ‡³šŸ‡±Netherlands @daffie
Created by

šŸ‡®šŸ‡³India tushar.k

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • šŸ‡ŗšŸ‡øUnited States aaronelborg

    I think I fixed this by updating to the latest and greatest Paragraphs module. Does that sound familiar to anyone else?

  • šŸ‡ØšŸ‡¦Canada paintingguy

    Deprecated function: addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Database\Connection->escapeLike() (line 1525 of core/lib/Drupal/Core/Database/Connection.php

    Iā€™m getting this when creating new registrations.

  • šŸ‡µšŸ‡°Pakistan tahirpatel

    It's not recommended to modify core files in Drupal. This can cause issues with future updates and maintenance of the site. Instead, you should create a patch file and add it to composer.

    here are the steps to create a patch file and add it to composer:

    Create a copy of the file Connection.php in the directory core/lib/Drupal/Core/Database to preserve the original file.

    Edit the Connection.php file and replace the following code:

    public function escapeLike($string) {
      return addcslashes($string, '\%_');
    }
    

    With:

    public function escapeLike($string) {
      if (!isset($string)) {
        return $string;
      }
      return addcslashes($string, '\%_');
    }
    

    Navigate to the root directory of your Drupal installation in the terminal/command prompt.

    Run the following command to create a patch file:

    git diff > path/to/your/patch/file.patch

    Replace path/to/your/patch/file.patch with the path where you want to save the patch file.

    Open the composer.json file located in the root directory of your Drupal installation.

    Add the following code to the extra section of the composer.json file:

    "patches": {
      "drupal/core": {
        "EscapeLike function": "path/to/your/patch/file.patch"
      }
    }
    

    Replace EscapeLike function with a short description of the patch, and path/to/your/patch/file.patch with the actual path where you saved the patch file.

    Save the composer.json file and run the following command to apply the patch:

    composer install

    This will download the latest version of Drupal core and apply the patch automatically. If you have already installed Drupal core, you can run composer update instead of composer install.

    That's it! The escapeLike() function will now return the original string if it is not set, and the patch will be applied automatically whenever you update or install Drupal core using composer.

  • šŸ‡µšŸ‡°Pakistan tahirpatel

    if patch not working you need to install 'cweagans/composer-patches'

    The cweagans/composer-patches package is a Composer plugin that allows you to apply patches to third-party packages that you've installed via Composer.

    To use this plugin, you can follow these steps:

    Install the cweagans/composer-patches package via Composer:
    composer require cweagans/composer-patches

    Add the patch to your composer.json file:

    {
        "extra": {
            "patches": {
                "drupal/core": {
                    "EscapeLike function fix": "patches/database-escapeLike.patch"
                }
            }
        }
    }
    

    Run 'composer install' or 'composer update drupal/core' to apply the patch.

  • šŸ‡µšŸ‡°Pakistan tahirpatel

    if the patch not applies, you need to install composer 'cweagans/composer-patches'.

    The cweagans/composer-patches package is a Composer plugin that allows you to apply patches to third-party packages that you've installed via Composer.

    To use this plugin, you can follow these steps:

    Install the cweagans/composer-patches package via Composer:
    composer require cweagans/composer-patches

    Add the patch to your composer.json file:

    {
        "extra": {
            "patches": {
                "drupal/core": {
                    "EscapeLike function fix": "patches/database-escapeLike.patch"
                }
            }
        }
    }
    

    Run composer install or composer update drupal/core to apply the patch.

  • šŸ‡µšŸ‡°Pakistan tahirpatel

    if the patch not applies, you need to install composer 'cweagans/composer-patches'.

    The cweagans/composer-patches package is a Composer plugin that allows you to apply patches to third-party packages that you've installed via Composer.

    To use this plugin, you can follow these steps:

    Install the cweagans/composer-patches package via Composer:
    composer require cweagans/composer-patches

    Add the patch to your composer.json file:

    {
        "extra": {
            "patches": {
                "drupal/core": {
                    "EscapeLike function fix": "patches/database-escapeLike.patch"
                }
            }
        }
    }
    

    Run composer install or composer update drupal/core to apply the patch.

Production build 0.71.5 2024