Skip to content

db.php deprecated use of function #77

Open

Description

@Zachify

There is a use of stripos() in db.php which can lead to an error:

Line 439 of db.php:

if ( false !== stripos( $query_match, $key ) ) {

As of PHP 7.3, the second parameter of stripos() cannot be an integer. I have had success overcoming this by casting the parameter as a string:

if ( false !== stripos( $query_match, (String)$key ) ) {

Activity

  1. dd32 commented on Oct 6, 2022

    @dd32
    Member

    It would be nice to know what query lead to triggering this.. as technically, this should not really be possible (although a similar notice would be)

    $key should be a table name, which is inherently a string, but it's likely false in this case as $this->get_table_from_query( $query ) probably failed..

    That doesn't explain why it's an integer, rather than a boolean though..

    Some code doing something like $wpdb->srtm[] = true would trigger your error though.

  2. Zachify commented on Oct 6, 2022

    @Zachify
    Author

    Unfortunately I cannot find the full query, just this snippet from my server's error log:
    stripos('SELECT * FROM w...', 0)

    This is The Events Calendar plugin's migration process that triggers this error, causing the migration to halt indefinitely.

    In a site without the HyperDB plugin, this migration performs as expected.

  3. ErikBrendel commented on Nov 25, 2026

    @ErikBrendel

    On PHP 8 this no longer shows a notice: the key 0 is cast to the needle "0", so after any table-less write (SET …) every query containing a 0 silently goes to the master. Fix and repro in #194.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions