Skip to content

Uninitialized Message properties #508

Closed
@TheLevti

Description

@TheLevti

Description

The following code:

$headers = $msg->headers;

Resulted in this output:

Typed property RdKafka\Message::$headers must not be accessed before initialization

But I expected this output instead:

[] or null

As the library switched to typed properties, it is critical that all of them are properly initialized either with null (if nullable) or with some default value. In this case https://github.com/arnaud-lb/php-rdkafka/blob/6.x/message_arginfo.h#L72 here you have not defined a default value for $msg->headers and because it is not initialized on construction, first access of this public property causes this error.

Suggestion: As this property is defined as an array, let it be initialized as an empty array by default or define this prop as nullable if no header information is present. (stub: https://github.com/arnaud-lb/php-rdkafka/blob/6.x/message.stub.php#L29)

Same for the public properties $err, $partition and $offset.

php-rdkafka Version

5.0.2 and 6.0.0

librdkafka Version

No response

PHP Version

PHP 8.0

Operating System

Debian

Kafka Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions