Skip to content

Fix: query builder treats column names like date/time as callbacks - #353

Merged
techmahedy merged 1 commit into
doppar:4.xfrom
abdulmajidcse:fix/builder-string-callables
Oct 7, 2026
Merged

techmahedy merged 1 commit into
doppar:4.xfrom
abdulmajidcse:fix/builder-string-callables

Conversation

@abdulmajidcse

@abdulmajidcse abdulmajidcse commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Pull Request Checklist

Q A
Branch? 4.x
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

Description

where(), orWhere(), if(), embed() and embedCount() used is_callable() to tell whether an argument is a callback. is_callable() also returns true for strings that name a PHP function, so ordinary column names and values were called as functions:

  • where('date', $x) called date($builder) and threw a TypeError. Columns named time, key, max, min, file, end and range failed the same way, in both Entity\Builder and Query\Builder.
  • ->if($request->input('filter'), …) with filter=phpinfo ran phpinfo() and printed the server configuration.
  • embed(['link', …]) with a relation named after a function called that function as the relation's constraint.

The fix adds a Grammar::isCallback() helper (!is_string($value) && is_callable($value)) and uses it at these sites. Closures, invokable objects and [$obj, 'method'] callables behave as before; only bare strings are no longer called.

Checklist

  • Tests have been added or updated (tests/Builder/StringArgumentNotCallableTest.php: 20 tests that fail on the old code and pass on the new)
  • Documentation has been updated if necessary (not needed)
  • Code follows the project coding standards
  • All tests pass locally (full suite and PHPStan)

where(), orWhere(), if(), embed() and embedCount() used is_callable() to detect callbacks, which is also true for strings naming a PHP function. Columns such as date, time, key, max or file were invoked as functions, and if() would call a function named by a string value.

Add Grammar::isCallback() so bare strings are never treated as callbacks; closures, invokable objects and array callables are unchanged.
@NazmusShakib

Copy link
Copy Markdown
Member

Thanks for this PR! We really appreciate your contribution. Our team will review it shortly.

@techmahedy techmahedy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @abdulmajidcse, great catch and a clear write-up. Treating strings as column names/values instead of callbacks is the right fix, and the tests for where/orWhere/if are solid. Merging this now.

@techmahedy
techmahedy merged commit 8cc3da2 into doppar:4.x Oct 7, 2026
16 checks passed
@abdulmajidcse
abdulmajidcse deleted the fix/builder-string-callables branch October 7, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants