Skip to content

Commit 1c8eb62

Browse files
Merge pull request #675 from MauricioFauth/fix/CustomJsonSerializer
Fix CustomJsonSerializer::extractObjectData() notice
2 parents 01eb01c + fd075d0 commit 1c8eb62

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎.github/workflows/lint-and-analyse-php.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
runs-on: ubuntu-latest
3737
strategy:
3838
matrix:
39-
php-version: [ '7.4' ]
39+
php-version: [ '7.2' ]
4040
steps:
4141
- name: Checkout code
4242
uses: actions/checkout@v6

‎src/Tools/CustomJsonSerializer.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Zumba\JsonSerializer\JsonSerializer;
1010

1111
use function in_array;
12+
use function method_exists;
1213

1314
use const PHP_VERSION_ID;
1415

@@ -45,6 +46,7 @@ class CustomJsonSerializer extends JsonSerializer
4546
'EVENT_OPTIONS',
4647
'USER_OPTIONS',
4748
'asciiMap',
49+
'trace',
4850
];
4951

5052
/**
@@ -65,11 +67,15 @@ protected function extractObjectData($value, $ref, $properties)
6567
}
6668

6769
try {
68-
$propRef = $ref->getProperty($property);
70+
$propRef = $this->getReflectionProperty($ref, $property);
6971
if (PHP_VERSION_ID < 80100) {
7072
$propRef->setAccessible(true);
7173
}
7274

75+
if (method_exists($propRef, 'isInitialized') && ! $propRef->isInitialized($value)) {
76+
continue;
77+
}
78+
7379
$data[$property] = $propRef->getValue($value);
7480
} catch (ReflectionException $e) {
7581
$data[$property] = $value->$property;

‎tests/data/parser/parseExplain14.out‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@
220220
"message": "Unrecognized statement type.",
221221
"code": 0,
222222
"file": "<project-root>/src/Parser.php",
223-
"line": 628
223+
"line": 628,
224+
"string": "",
225+
"previous": null
224226
}
225227
]
226228
},

‎tests/data/parser/parseExplainErr1.out‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@
137137
"message": "An expression was expected.",
138138
"code": 0,
139139
"file": "<project-root>/src/Parser.php",
140-
"line": 628
140+
"line": 628,
141+
"string": "",
142+
"previous": null
141143
},
142144
{
143145
"@type": "PhpMyAdmin\\SqlParser\\Exceptions\\ParserException",
@@ -147,7 +149,9 @@
147149
"message": "An expression was expected.",
148150
"code": 0,
149151
"file": "<project-root>/src/Parser.php",
150-
"line": 628
152+
"line": 628,
153+
"string": "",
154+
"previous": null
151155
}
152156
]
153157
},

0 commit comments

Comments
 (0)