Repository navigation
Conversation
bind() takes the value by reference, so literals cannot be bound
(bind(':id', 5) is a fatal error), and binding a loop variable binds every
placeholder to its final value. bindValue() binds a copy of the value. The
by-reference behaviour of bind() is now documented in its docblock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary of Changes
DatabaseQuery::bind()takes$valueby reference. That is intentional (output parameters, rebinding a variable between executions), but it means:$query->bind(':id', 5)is a fatal error;Users work around it with temporary variables or misuse
bindArray(). The newbindValue($key, $value, $dataType = ParameterType::STRING, $length = 0, $driverOptions = [])binds a copy of the value: it is a by-value proxy tobind(), so it supports the same arguments (including arrays of keys and values). New API gets native parameter types and returnsstatic. The by-reference semantics ofbind()are now spelled out in its docblock.bindValue()is added toDatabaseQueryonly. Adding it toQueryInterfacewould break other implementations of the interface, so that is a 5.0 change.Alternative to #357 (HLeithner), which adds the same proxy but still needed attribute-based tests.
Testing Instructions
New
DatabaseQueryTest::testBindValuebinds a literal and three values from a loop and checks that each binding keeps its own value (vendor/bin/phpunit Tests/DatabaseQueryTest.php).Documentation Changes Required
None on
4.x-dev(no page there documents binding yet). #373 states "There is nobindValue()" indocs/overview.md→ "Things to know before you build on this" and describes the workarounds indocs/parameters-and-escaping.md→ "Binding by reference"; when the second of the two is merged, both should point tobindValue()instead.🤖 Generated with Claude Code