[PHP] Problem with serializing Proto objects using igbinary
I am using PHP 8.3 with the ext-protobuf 3.21.1 extension in the project. OS: Linux
The problem is that when serializing a generated PHP object based on a Protobuf Message, its content is not read. Serialization in the project is performed using igbinary_serialize.
I have two example code fragments: one interacts with a Protobuf object (which inherits from \Google\Protobuf\Internal\Message), and the other interacts with an object created from a standard PHP class. In the first case, igbinary cannot read the value set in the Protobuf object during serialization, whereas in the second case, serialization proceeds without any issues.
First case:
<?php
declare(strict_types=1);
$timestamp = new Google\Protobuf\Timestamp();
$timestamp->setSeconds(1719822351);
$serializedData = igbinary_serialize($timestamp);
echo 'Igbinary serialized data: '.$serializedData.PHP_EOL;
echo 'Set seconds value in object: '.$timestamp->getSeconds().PHP_EOL;
Result:
Igbinary serialized data: Google\Protobuf\Timestamp
Set seconds value in object: 1719822351
Second case:
<?php
declare(strict_types=1);
class Timestamp
{
protected int $seconds = 0;
public function setSeconds(int $seconds): void
{
$this->seconds = $seconds;
}
public function getSeconds(): int
{
return $this->seconds;
}
}
$timestamp = new Timestamp();
$timestamp->setSeconds(1719822351);
$serializedData = igbinary_serialize($timestamp);
echo 'Igbinary serialized data: '.$serializedData.PHP_EOL;
echo 'Set seconds value in object: '.$timestamp->getSeconds().PHP_EOL;
Result:
Igbinary serialized data: Timestamp
*seconds
f�h
Set seconds value in object: 1719822351
Can I achieve the correct serialization result as shown in the second example?
Similar topics: https://github.com/protocolbuffers/protobuf/issues/14872, https://github.com/protocolbuffers/protobuf/issues/12714, https://github.com/protocolbuffers/protobuf/pull/12718
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.
Hello, the problem is still relevant, I would like to figure it out and find a solution
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.
This issue is still active
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.
This issue is still active
This seems to be an extension issue; the properties of the object are not available (if you do a var_dump($timestamp) you will see no property either)
This is a problem for caching or debugging
Can we make proto serializable and natively json serializable as well?
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.
This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.