I am running PHP 5.6.30 and getting the following error with the extension v3.2.0.a.1. The code works fine on PHP 7.1.1 with the package version of the lib. Here is my proto file:
PHP Fatal error: Generated message class \0rotobufBenchmarks\-essage\Person hasn't been defined in /pb-performance-comparison/src/GPBMetadata/Person.php on line 29
PHP Stack trace:
PHP 1. {main}() /pb-performance-comparison/vendor/athletic/athletic/bin/athletic:0
PHP 2. Athletic\Athletic->run() /pb-performance-comparison/vendor/athletic/athletic/bin/athletic:19
PHP 3. Athletic\Athletic->benchmark() /pb-performance-comparison/vendor/athletic/athletic/src/Athletic/Athletic.php:38
PHP 4. Athletic\Runners\SuiteRunner->runSuite() /pb-performance-comparison/vendor/athletic/athletic/src/Athletic/Athletic.php:61
PHP 5. Athletic\Runners\SuiteRunner->runClass() /pb-performance-comparison/vendor/athletic/athletic/src/Athletic/Runners/SuiteRunner.php:59
PHP 6. Athletic\Runners\ClassRunner->run() /pb-performance-comparison/vendor/athletic/athletic/src/Athletic/Runners/SuiteRunner.php:74
PHP 7. Athletic\AthleticEvent->run() /pb-performance-comparison/vendor/athletic/athletic/src/Athletic/Runners/ClassRunner.php:58
PHP 8. ProtobufBenchmarks\EncodeEvent->classSetUp() /pb-performance-comparison/vendor/athletic/athletic/src/Athletic/AthleticEvent.php:77
PHP 9. ProtobufBenchmarks\Person->GenerateProto() /pb-performance-comparison/src/ProtobufBenchmarks/EncodeEvent.php:38
PHP 10. ProtobufBenchmarks\Message\Person->__construct() /pb-performance-comparison/src/ProtobufBenchmarks/Person.php:28
PHP 11. GPBMetadata\Person::initOnce() /pb-performance-comparison/src/ProtobufBenchmarks/Message/Person.php:34
PHP 12. Google\Protobuf\Internal\DescriptorPool->internalAddGeneratedFile() /pb-performance-comparison/src/GPBMetadata/Person.php:29
syntax = "proto3";
package ProtobufBenchmarks.Message;
message Person {
string name = 1;
int32 id = 2;
string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
string number = 1;
PhoneType type = 2;
}
repeated PhoneNumber phone = 4;
}
Any advice would be appreciated.
不要再你的message中嵌套message,我现在遇到的也是这个问题,我尝试将message 分离之后,情况会有所改变。
message TestMessage {
optional int32 a = 1;
message NestedMessage {...}
}
The compiler will generate the following classes:
class TestMessage {
public a;
}
// PHP doesn’t support nested classes.
class TestMessage_NestedMessage {...}
@TaoSunkist then why does it work for the package version of the library? It seems rather unexpected for it to work within one and not the other within the same version.
@TaoSunkist I did some research and PHP not supporting nested classes is not the reason this failed as when messages are nested in proto files, they are created with an underscore for the nested message.
I think this has been fixed in 3.3.x branch.
I guess the work around is: ProtobufBenchmarks.Message => protobufbenchmarks.message
Close this for now. Let me know if this has not been fixed.
@TeBoring I have the same problem,protobuf 3.6,1
Fatal error: Generated message class Picture\PictureResponse hasn't been defined in /home/tlt/grpc_test/GPBMetadata/Picture.php on line 28