Skip to content

Commit

Permalink
Fix parameter type (#74)
Browse files Browse the repository at this point in the history
* Fix parameter type

* Apply fixes from StyleCI

* Add test

* Add CHANGELOG

Co-authored-by: StyleCI Bot <bot@styleci.io>
Co-authored-by: Alexey Rogachev <arogachev90@gmail.com>
  • Loading branch information
3 people committed Oct 20, 2022
1 parent b696309 commit 1231422
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -2,7 +2,7 @@

## 1.3.1 under development

- no changes in this release.
- Enh #74: Add support for integer property names (@xepozz)


## 1.3.0 September 22, 2022
Expand Down
5 changes: 4 additions & 1 deletion src/VarDumper.php
Expand Up @@ -388,8 +388,11 @@ private function exportJson(mixed $var, bool $format, int $depth, int $level): m
}
}

private function getPropertyName(string $property): string
private function getPropertyName(string|int $property): string
{
if (is_int($property)) {
return (string) $property;
}
$property = str_replace("\0", '::', trim($property));

if (str_starts_with($property, '*::')) {
Expand Down
13 changes: 13 additions & 0 deletions tests/VarDumperTest.php
Expand Up @@ -799,6 +799,9 @@ public function asJsonDataProvider(): array
$incompleteObject = unserialize('O:16:"nonExistingClass":0:{}');
$incompleteObjectId = spl_object_id($incompleteObject);

$integerPropertyObject = unserialize('O:8:"stdClass":1:{i:5;i:5;}');
$integerPropertyObjectId = spl_object_id($integerPropertyObject);

$emptyObject = new stdClass();
$emptyObjectId = spl_object_id($emptyObject);

Expand Down Expand Up @@ -838,6 +841,16 @@ public function asJsonDataProvider(): array
}
JSON,
],
'integer property object' => [
$integerPropertyObject,
<<<JSON
{
"\$__id__\$": "{$integerPropertyObjectId}",
"\$__class__\$": "stdClass",
"5": 5
}
JSON,
],
'empty object' => [
$emptyObject,
<<<JSON
Expand Down

0 comments on commit 1231422

Please sign in to comment.