mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Use strings for numeric string key offsets
This commit is contained in:
parent
d0fc48cfaf
commit
a253463ba8
@ -125,7 +125,7 @@ class ObjectLike extends \Psalm\Type\Atomic
|
||||
$key_types = [];
|
||||
|
||||
foreach ($this->properties as $key => $_) {
|
||||
if (is_int($key) || preg_match('/^\d+$/', $key)) {
|
||||
if (is_int($key)) {
|
||||
$key_types[] = new Type\Atomic\TInt();
|
||||
} else {
|
||||
$key_types[] = new Type\Atomic\TString();
|
||||
@ -166,7 +166,7 @@ class ObjectLike extends \Psalm\Type\Atomic
|
||||
$value_type = null;
|
||||
|
||||
foreach ($this->properties as $key => $property) {
|
||||
if (is_int($key) || preg_match('/^\d+$/', $key)) {
|
||||
if (is_int($key)) {
|
||||
$key_types[] = new Type\Atomic\TInt();
|
||||
} else {
|
||||
$key_types[] = new Type\Atomic\TString();
|
||||
|
@ -101,6 +101,14 @@ class ArrayAccessTest extends TestCase
|
||||
takesBool($b[2]);
|
||||
}',
|
||||
],
|
||||
'stringKeysWithInts' => [
|
||||
'<?php
|
||||
$array = ["01" => "01", "02" => "02"];
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
$len = strlen($key);
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user