Fix/where column name collision#55
Merged
Merged
Conversation
where() used is_callable($column) to detect nested-group closures, but column names that collide with built-in PHP functions (key, list, count, current, ...) made is_callable() return true. Such columns were wrongly routed into whereNested(), triggering 'Calling key() on an object is deprecated' on PHP 8.1+. Detect nested groups with $column instanceof \Closure instead. A plain string is always a column name now. Also align first()/find() to return null (not false) when no row matches, matching Model::find() and supporting ModelBuilder's ?Model return type. Adds regression tests for key/count/list column names and verifies that Closure-based nested groups still work. Fixes #53
…rrays is_callable() returns true for strings matching built-in PHP function names (key, list, count, ...), so Collection::contains() and Builder::join() wrongly treated such column names as callbacks. Detect \Closure instead. whereExists() switched to \Closure too for consistency. Same root cause as the earlier where() fix. Empty whereIn([])/whereNotIn([]) compiled to 'IN ()', a syntax error on MySQL and PostgreSQL that silently passed on SQLite. Now compiles to '1 = 0' (empty IN, always false) and '1 = 1' (empty NOT IN, always true), valid on all drivers. Adds regression tests for function-named columns, contains() variants, and empty IN/NOT IN arrays. Fixes #54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.