1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Use strings for numeric string key offsets

This commit is contained in:
Matt Brown 2018-03-15 10:16:11 -04:00
parent d0fc48cfaf
commit a253463ba8
2 changed files with 10 additions and 2 deletions

View File

@ -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();

View File

@ -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);
}',
],
];
}