Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parameter type #74

Merged
merged 4 commits into from Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there int property names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
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