Warning: addcslashes() expects parameter 1 to be string, array given in DatabaseConnection->escapeLike()

Created on 25 May 2018, about 6 years ago
Updated 6 April 2023, about 1 year ago

This warning appear when i save any translation

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇮🇹Italy Riki72

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

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.

  • 🇨🇦Canada nedjo

    Thanks for reporting this issue and submitting a patch.

    Confirming that the patch at #15 🐛 Warning: addcslashes() expects parameter 1 to be string, array given in DatabaseConnection->escapeLike() Fixed correctly addresses what is clearly an error in the code. Nice!

    More specifically:

    • Currently, in i18nviews_translate_page_form(), views_invalidate_cache() is registered as a form submit handler.
    • The first argument passed to a form submit callback is a form array.
    • However, the first argument to views_invalidate_cache() is an optional cache ID string, with a default value provided. As a result, an invalid value (a form array) is passed in.
    • The proposed fix - register a new form submit callback and, from there, call views_invalidate_cache() - correctly addresses this error.

    Exactly how does this fix relate to the reported error? That's a bit more involved. Here are the specific steps:

    1. When invoked as a form submit callback, views_invalidate_cache() calls cache_clear_all($cid), feeding the form array as $cid.
    2. cache_clear_all() loads a database cache object and calls its ::clear() method return _cache_get_object($bin)->clear($cid, $wildcard);
    3. ::clear() method calls db_like() as part of generating an argument value: db_delete($this->bin)->condition('cid', db_like($cid) . '%', 'LIKE')->execute();
    4. db_like() calls the database connection object's ::escapeLike() method.
    5. The ::escapeLike() method calls addslashes(), feeding an array rather than a string, and thus triggers the error.

    Nitpick: it would be nice to have a "docblock" for the new form submit callback.

  • Status changed to Fixed about 1 year ago
  • 🇨🇦Canada nedjo

    Thx, applied.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024