Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP package error #3182

Closed
woding opened this issue Jun 5, 2017 · 8 comments
Closed

PHP package error #3182

woding opened this issue Jun 5, 2017 · 8 comments
Labels

Comments

@woding
Copy link

woding commented Jun 5, 2017

PHP VERSION 7.1.5
libprotoc 3.3.0

the common.proto file
`syntax = "proto3";

message requestHeader
{
uint32 api = 1;
string version = 10;
string vkey = 11;
uint32 vmid = 12;
}`

the loadInit.proto file
`syntax = "proto3";

package system;

import "common.proto";

message loadInitRequest
{
message parameter
{
string SToken = 1;
}
requestHeader header = 1;
parameter param = 2; //SToken
}`

and generate code
protoc --proto_path=proto/ --php_out=gen/ proto/common.proto proto/loadInit.proto

the composer.json file
{ "name": "TP", "description": "test protobuf", "type": "project", "autoload": { "psr-4": { "Google\\Protobuf\\Internal\\": "vendor/protobuf/Google/Protobuf/Internal", "GPBMetadata\\Google\\Protobuf\\Internal\\": "vendor/protobuf/GPBMetadata/Google/Protobuf/Internal", "GPBMetadata\\" : "gen/GPBMetadata/", "System\\" : "gen/System" }, "files": [ "vendor/protobuf/Google/Protobuf/descriptor.php" ] } }
then try to run following php code:
`include DIR.'/vendor/autoload.php';

$req = new System\loadInitRequest();
var_dump($req);`

get following error:

Notice: Undefined index: System\loadInitRequest in /media/sf_wwwroot/test/vendor/protobuf/Google/Protobuf/Internal/DescriptorPool.php on line 112

Fatal error: Uncaught Error: Call to a member function getField() on null in /media/sf_wwwroot/test/vendor/protobuf/Google/Protobuf/Internal/Message.php:75 Stack trace: #0 /media/sf_wwwroot/test/gen/System/loadInitRequest.php(31): Google\Protobuf\Internal\Message->__construct() #1 /media/sf_wwwroot/test/index.php(4): System\loadInitRequest->__construct() #2 {main} thrown in /media/sf_wwwroot/test/vendor/protobuf/Google/Protobuf/Internal/Message.php on line 75

@TeBoring TeBoring added the php label Jun 5, 2017
@fisnikhajredini
Copy link

any fixes yet? having the same problem here.

@TeBoring
Copy link
Contributor

TeBoring commented Aug 5, 2017

Does rename the message using first-upper camel case fix the problem?

@fisnikhajredini
Copy link

in my case, i already have the message using camel case:

$protoClass = new odcore_data_dmcp_ModuleStatistics();

@TeBoring
Copy link
Contributor

TeBoring commented Aug 5, 2017

odcore_data_dmcp_ModuleStatistics is not camel case.

@fisnikhajredini
Copy link

Okay, the underscores confuse me on that.
I am receiving messages from another server, i only need to decode the messages, using the encoded msg that i receive, therefore i used the exact same name. Would changing it make any difference in the decoding process? If no, i guess "moduleStatisics" would be a camel case?

@TeBoring
Copy link
Contributor

TeBoring commented Aug 5, 2017

A first-upper camel case should be ModuleStatisics

@fisnikhajredini
Copy link

That worked. Thanks

@TeBoring
Copy link
Contributor

TeBoring commented Aug 6, 2017

Awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants