Packing and merging from JSON string operations fail for the Any class when the c extension is installed. Code to reproduce two error cases is below.
Case 1: Packing
<?php
require __DIR__ . '/vendor/autoload.php';
if (extension_loaded('protobuf')) {
echo 'Protobuf ext ver: ' . phpversion('protobuf') . "\n";
} else {
echo "Protobuf ext not loaded\n";
}
$fieldMask = new \Google\Protobuf\FieldMask();
$any = new \Google\Protobuf\Any();
$any->pack($fieldMask);
echo "done\n";
Output:
Protobuf ext ver: 3.5.1.1
PHP Fatal error: Given value is not an instance of Message. in anytest.php on line 14
Case 2: mergeFromJsonString
<?php
require __DIR__ . '/vendor/autoload.php';
if (extension_loaded('protobuf')) {
echo 'Protobuf ext ver: ' . phpversion('protobuf') . "\n";
} else {
echo "Protobuf ext not loaded\n";
}
// Construct a field mask object so that it is added to the
// descriptor pool - otherwise we see a failure
$fieldMask = new \Google\Protobuf\FieldMask();
$jsonStr = '{"@type":"type.googleapis.com/google.protobuf.FieldMask","value":""}';
$any = new \Google\Protobuf\Any();
$any->mergeFromJsonString($jsonStr);
Output:
Protobuf ext ver: 3.5.1.1
PHP Fatal error: Uncaught Exception: Error occurred during parsing: No such field: @type
in anytest2.php:17
Composer file
{
"require": {
"google/protobuf": "^3.5.2"
}
}
PHP version
$ php --version
PHP 7.0.11 (cli) (built: Feb 21 2018 13:30:06) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.11, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans
Packing and merging from JSON string operations fail for the Any class when the c extension is installed. Code to reproduce two error cases is below.
Case 1: Packing
Output:
Case 2: mergeFromJsonString
Output:
Composer file
PHP version