Repository navigation
Conversation
DataSet accepts string offsets, but key() was declared int|bool|null. As the file does not use strict types, every string key was coerced to true, so foreach over an associative set lost its keys. Allow string in the return type; bool stays so that subclasses overriding key() with the 4.0.0 signature remain compatible. 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
DataSetaccepts string offsets (constructor,offsetSet()), butkey()is declaredint|bool|null. BecauseDataSet.phpdoes not use strict types, PHP coerces every string key totrueon return, soforeach (new DataSet(['a' => $obj]) as $k => $v)gives$k === true. Every associative set loses its keys in aforeach.This widens the return type to
int|string|bool|null. Widening a return type is backward compatible for callers.boolis kept on purpose (rather than switching toint|string|nulland returningnullfor "no current element") so that subclasses which overridekey()with the 4.0.0 signatureint|bool|nullstay compatible; droppingboolcan happen in 5.0.Testing Instructions
DataSetTest::testIterationKeepsStringKeys()iterates a set keyed'first','second',3and expects exactly those keys. Before the change it fails with['first', 'second', 3]vs[true, true, 3]; after, it passes.Documentation Changes Required
docs/v3-to-v4-update.md: thekey()section described aTypeError; the actual 4.0.0 behaviour is the silent coercion totrue. It now says so and that later 4.x releases accept string keys again.🤖 Generated with Claude Code