php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78332 Int in JSON message formatted as string
Submitted: 2019-07-24 13:40 UTC Modified: 2020-12-20 04:22 UTC
From: fi at facelift-bbt dot com Assigned: cmb (profile)
Status: No Feedback Package: PECL (PECL)
PHP Version: 7.2.20 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: fi at facelift-bbt dot com
New email:
PHP Version: OS:

 

 [2019-07-24 13:40 UTC] fi at facelift-bbt dot com
Description:
------------
When producing an encoded JSON object that contains an integer field, the consumer always receives the field as string.

Producer: {"id":1639}
Consumer: {"id":"1639"}

Test script:
---------------
$message = '{"id":1639}';

$producer = new RdKafka\Producer();
$topic = $producer->newTopic('myTopic');
$topic->produce(RD_KAFKA_PARTITION_UA, 0, $message);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-24 13:54 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2019-07-24 13:54 UTC] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2019-07-24 14:14 UTC] fi at facelift-bbt dot com
-Status: Feedback +Status: Open
 [2019-07-24 14:14 UTC] fi at facelift-bbt dot com
Test script:
---------------
<?php

$message = '{"id":1639}';

$producer = new RdKafka\Producer();
$topic = $producer->newTopic('myTopic');
$topic->produce(RD_KAFKA_PARTITION_UA, 0, $message);

?>
 [2019-07-24 14:21 UTC] cmb@php.net
-Package: *General Issues +Package: PECL
 [2019-07-24 15:24 UTC] danack@php.net
-Status: Open +Status: Feedback
 [2019-07-24 15:24 UTC] danack@php.net
Hi - the script you provided does not run, https://3v4l.org/XUMYj . It gives the error Fatal error: Uncaught Error: Class 'RdKafka\Producer' not found in /in/XUMYj:5

Running json_decode simply as you described it gives: https://3v4l.org/2VPX6 which appears to give an int.

You might find reading this http://sscce.org/ helpful as a guide on how to write a self-contained reproduce case.
 [2019-07-24 15:58 UTC] cmb@php.net
-Status: Feedback +Status: Open
 [2019-07-24 15:58 UTC] cmb@php.net
This is about https://pecl.php.net/package/rdkafka.
 [2019-07-25 06:43 UTC] fi at facelift-bbt dot com
Serializing and deserializing in PHP works well, yes.
But after processing the serialized JSON object with the Kafka producer and reading the message in a consumer written in Java, the int field has been transformed into a string - before deserializing.
 [2020-12-07 12:33 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-12-07 12:33 UTC] cmb@php.net
Is this still an issue with latest rdkafka and any of the actively
supported PHP versions[1]?  If so, you may be better off to report
that as issue on the Github repo[2].

[1] <https://www.php.net/supported-versions.php>
[2] <https://github.com/arnaud-lb/php-rdkafka>
 [2020-12-20 04:22 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 13:01:30 2024 UTC