Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation warning when using regexp operator in where clause #11294

Open
joshdaugherty opened this issue Dec 20, 2024 · 0 comments
Open

Deprecation warning when using regexp operator in where clause #11294

joshdaugherty opened this issue Dec 20, 2024 · 0 comments
Labels

Comments

@joshdaugherty
Copy link

Bug description

When I use the regex operator in a where clause...

$query->where('foo', 'regexp', '^bar$');

... I get the following log warning:

LOG.warning: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in ...statamic\cms\src\Query\Builder.php on line 702

The error is likely caused by some entries not having the 'foo' field/column, resulting in a null value being passed to the preg_match function.

It seems like the work from this v3.3.12 commit could be extended to the filterTestLikeRegex() function in cms/src/Query
/Builder.php: 1cde722.

Current:

    protected function filterTestLikeRegex($item, $pattern)
    {
        return preg_match("/{$pattern}/im", $item);
    }

Proposed:

    protected function filterTestLikeRegex($item, $pattern)
    {
        return preg_match("/{$pattern}/im", (string) $item);
    }

How to reproduce

  1. Create at least one Entry with a value for a given field (e.g., handle: 'foo').
  2. Create at least one separate Entry with no value for the same field from step 1.
  3. Create a query scope using the where method; with the field handle from steps 1 and 2 in the first argument; and using the regexp operator in a where method (e.g., $query->where('foo', 'regexp', '^bar$');
  4. Apply that query scope to an Entries field, configuring that field to allow it to select from the collection of the entries from steps 1 and 2.
  5. Edit an entry/tag/etc. (or create a new one) that uses the field from step 4.
  6. While editing the entry/tag/etc. from step 5, check the debug bar messages for the field from step 4 and presumably see LOG.warning: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in ...statamic\cms\src\Query\Builder.php on line 702

Logs

No response

Environment

Environment
Application Name: UAMS Statamic Sandbox
Laravel Version: 11.35.0
PHP Version: 8.2.26
Composer Version: 2.8.3
Environment: local
Debug Mode: ENABLED
URL: uams-statamic-sandbox.test
Maintenance Mode: OFF
Timezone: America/Chicago
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 7
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.42.1 PRO

Statamic Addons
jacksleight/statamic-bard-mutator: 3.0.3
statamic/importer: 1.5.1
statamic/ssg: 3.1.0
studio1902/statamic-peak-browser-appearance: 3.6.0
studio1902/statamic-peak-commands: 8.12.0
studio1902/statamic-peak-seo: 8.18.0
studio1902/statamic-peak-tools: 6.6.0

Installation

Starter Kit using via CLI

Additional details

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants