Home > Backend Development > PHP Tutorial > protocol-buffer - Problems encountered when upgrading protocolbuffers extension to php7?

protocol-buffer - Problems encountered when upgrading protocolbuffers extension to php7?

WBOY
Release: 2016-09-08 08:43:55
Original
1049 people have browsed it

Background

Since protocolbuffers are being used in the project, the extensions used in the entire project basically support php7. Only protocolbuffers does not support php7. The original author has stopped maintaining the extension, and has no choice but to start researching how to extend protocolbuffers. Version 5.x is upgraded to php7. The extension currently compiles. github

The results of make test are as follows:

<code>Number of tests :  144               144
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :   67 ( 46.5%) ( 46.5%)
Expected fail   :    0 (  0.0%) (  0.0%)
Tests passed    :   77 ( 53.5%) ( 53.5%)</code>
Copy after login
Copy after login

Problems encountered

The following is the test code:

<code><?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . "messages" . DIRECTORY_SEPARATOR . "field_int32.proto.php";

$bytes = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . "fixtures" . DIRECTORY_SEPARATOR . "001_int32_init.bin");

$u = new Tutorial_Integer32();
$u->setValue(0);

$obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes);
var_dump($obj);
if ($obj instanceof Tutorial_Integer32) {
    var_dump($obj->getValue());
    if ($obj->getValue() == 0) {
        echo "OK" . PHP_EOL;
    } else {
        var_dump($obj);
    }
} else {
    var_dump($obj);
}

ini_set("protocolbuffers.native_scalars", 1);
$obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes);

if ($obj instanceof Tutorial_Integer32) {
    var_dump($obj->getValue());
    if ($obj->getValue() === 0) {
        echo "OK" . PHP_EOL;
    } else {
        var_dump($obj);
    }
} else {
    var_dump($obj);
}

</code>
Copy after login
Copy after login

The output results are as follows:

<code>object(Tutorial_Integer32)#2 (2) {
  ["_properties":protected]=>
  array(0) {
  }
  ["value":protected]=>
  string(1) "0"
}
NULL
OK
NULL
object(Tutorial_Integer32)#3 (2) {
  ["_properties":protected]=>
  array(0) {
  }
  ["value":protected]=>
  int(0)
}</code>
Copy after login
Copy after login

Problem summary: When protocolbuffers::decode, the parsed object can be returned, but the properties of the object cannot be read. Solving. . .

Reply content:

Background

Since protocolbuffers are being used in the project, the extensions used in the entire project basically support php7. Only protocolbuffers does not support php7. The original author has stopped maintaining the extension, and has no choice but to start researching how to extend protocolbuffers. Version 5.x is upgraded to php7. The extension currently compiles. github

The results of make test are as follows:

<code>Number of tests :  144               144
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :   67 ( 46.5%) ( 46.5%)
Expected fail   :    0 (  0.0%) (  0.0%)
Tests passed    :   77 ( 53.5%) ( 53.5%)</code>
Copy after login
Copy after login

Problems encountered

The following is the test code:

<code><?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . "messages" . DIRECTORY_SEPARATOR . "field_int32.proto.php";

$bytes = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . "fixtures" . DIRECTORY_SEPARATOR . "001_int32_init.bin");

$u = new Tutorial_Integer32();
$u->setValue(0);

$obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes);
var_dump($obj);
if ($obj instanceof Tutorial_Integer32) {
    var_dump($obj->getValue());
    if ($obj->getValue() == 0) {
        echo "OK" . PHP_EOL;
    } else {
        var_dump($obj);
    }
} else {
    var_dump($obj);
}

ini_set("protocolbuffers.native_scalars", 1);
$obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes);

if ($obj instanceof Tutorial_Integer32) {
    var_dump($obj->getValue());
    if ($obj->getValue() === 0) {
        echo "OK" . PHP_EOL;
    } else {
        var_dump($obj);
    }
} else {
    var_dump($obj);
}

</code>
Copy after login
Copy after login

The output results are as follows:

<code>object(Tutorial_Integer32)#2 (2) {
  ["_properties":protected]=>
  array(0) {
  }
  ["value":protected]=>
  string(1) "0"
}
NULL
OK
NULL
object(Tutorial_Integer32)#3 (2) {
  ["_properties":protected]=>
  array(0) {
  }
  ["value":protected]=>
  int(0)
}</code>
Copy after login
Copy after login

Problem summary: When protocolbuffers::decode, the parsed object can be returned, but the properties of the object cannot be read. Solving. . .

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template