protocolbuffers / protocolbuffers/protobuf

PHP Extension - Constructor cannot convert optional to string

Open
#26,824 1 comment 1 reaction 1 assignee View on GitHub

@bshaffer is already working on this.

Since Apr 14, 2026.

bug php
Dominant language
C++
Stars
72k
Forks
16.3k
Avg merge
1d 17h
Merged PRs (30d)
140

Description

This is a follow up to https://github.com/protocolbuffers/protobuf/issues/20000

When the constructor is called with null values

new TestMessage([
    'optional_bool' => null,
    'optional_bytes' => null,
    'optional_string' => null,
]);

#  Cannot convert '' to string

The added typehints prevent the original issue when using a setter
but it seems to still be an issue for constructor since extension bypassed the php setter :

Not sure what the best approach is here for now I have variation of my original fix here: ee05655

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.