This is an automated email from the ASF dual-hosted git repository.
mattiabasone pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/main by this push:
new 840dc8139f PHP - fix json_decode syntax error and set dev tools
version (#3824)
840dc8139f is described below
commit 840dc8139f4b3d1bfa8e8c8f1ac3be949b440634
Author: Mattia Basone <[email protected]>
AuthorDate: Fri Jun 19 11:48:20 2026 +0200
PHP - fix json_decode syntax error and set dev tools version (#3824)
---
composer.json | 6 +++---
lang/php/lib/Schema/AvroSchema.php | 19 ++++++++++++-------
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/composer.json b/composer.json
index ec5d2a3f37..a90db7b714 100644
--- a/composer.json
+++ b/composer.json
@@ -35,9 +35,9 @@
"ext-xml": "*",
"ext-curl": "*",
"ext-pcntl": "*",
- "rector/rector": "^2.2",
- "friendsofphp/php-cs-fixer": "^3.89",
- "phpstan/phpstan": "^2.1"
+ "rector/rector": "2.4.6",
+ "friendsofphp/php-cs-fixer": "3.95.8",
+ "phpstan/phpstan": "2.2.2"
},
"autoload": {
"psr-4": {
diff --git a/lang/php/lib/Schema/AvroSchema.php
b/lang/php/lib/Schema/AvroSchema.php
index 9471acd56d..aec38910a9 100644
--- a/lang/php/lib/Schema/AvroSchema.php
+++ b/lang/php/lib/Schema/AvroSchema.php
@@ -332,12 +332,17 @@ class AvroSchema implements \Stringable
*/
public static function parse(string $json): self
{
- $schemata = new AvroNamedSchemata();
-
- return self::realParse(
- avro: json_decode($json, true, JSON_THROW_ON_ERROR),
- schemata: $schemata
- );
+ try {
+ return self::realParse(
+ avro: json_decode($json, associative: true, flags:
JSON_THROW_ON_ERROR),
+ schemata: new AvroNamedSchemata()
+ );
+ } catch (\JsonException $e) {
+ throw new AvroSchemaParseException(
+ message: 'Invalid JSON string for schema.',
+ previous: $e
+ );
+ }
}
/**
@@ -351,7 +356,7 @@ class AvroSchema implements \Stringable
array|string|null $avro,
?string $defaultNamespace = null,
AvroNamedSchemata $schemata = new AvroNamedSchemata()
- ): AvroSchema {
+ ): self {
if (is_array($avro)) {
$type = $avro[self::TYPE_ATTR] ?? null;