Repository navigation
[ds] Fix incorrect numeric string key caution on Ds\Map pages - #54
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
The Ds\Map::get(), Ds\Map::put() and Ds\Map::remove() pages warned that
when using array syntax, scalar keys are coerced to integers by the
engine, so that $map["1"] would access int(1). This is not the case:
Ds\Map implements the dimension handlers natively and receives the
offset unchanged, and the engine does not cast numeric string offsets
for objects either (the same holds for the userland polyfill, which
implements ArrayAccess). $map["1"] and $map->get("1") both look up the
string key "1", and $map["1"] and $map[1] are two different keys.
Verified against ext-ds built from master on PHP 8.5: reading, writing,
isset() and unset() with array syntax all keep "1" and 1 distinct.
ext-ds requires PHP 8.2 or later, so the warning does not apply to any
supported version.
Replace the caution with a note stating the actual behavior, since
it differs from arrays, where such keys are cast to integers. Also
correct the array syntax note on the remove() page, which showed
reading a value ($map["key"]) instead of removing it
(unset($map["key"])).
Fixes php#22
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.
The
Ds\Map::get(),Ds\Map::put()andDs\Map::remove()pages had a caution saying that, with array syntax, scalar keys are coerced to integers, so$map["1"]would accessint(1). That is not true.Ds\Mapimplements the dimension handlers natively and receives the offset unchanged. The engine doesn't cast numeric string offsets for objects either, so the userland polyfill (ArrayAccess) behaves the same way.I checked this against ext-ds built from
masteron PHP 8.5:ext-ds requires PHP 8.2+, so the caution doesn't apply to any supported version.
Changes:
remove()page. It showed reading a value ($map["key"]) instead of removing it (unset($map["key"])).Validation:
php doc-base/configure.php --disable-libxml-check --enable-xml-details --redirect-stderr-to-stdout --with-base-lang=extensions;docbook-cson the diff; rendered the three pages with PhD and checked the output.Fixes #22