php - 在 php 中构造之前会运行什么代码?
问题描述
我正在学习grpc,但是我发现了一些奇怪的问题。
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: order.proto
namespace Order;
use Google\Protobuf\Internal\GPBUtil;
class Test extends \Google\Protobuf\Internal\Message
{
private $student_id = '';
public function __construct($data = NULL)
{
echo 'test message';
exit;
\GPBMetadata\Order::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>string student_id = 1;</code>
*
* @return string
*/
public function getStudentId()
{
return $this->student_id;
}
/**
* Generated from protobuf field <code>string student_id = 1;</code>
*
* @param string $var
* @return $this
*/
public function setStudentId($var)
{
GPBUtil::checkString($var, True);
$this->student_id = $var;
return $this;
}
}
require __DIR__ . '/vendor/autoload.php';
$test = new \Order\Test();
当我执行上面的代码时,我无法得到'测试消息';
但是,当我从“测试”类中删除“扩展”时,我可以得到它。
它出什么问题了 ?一些代码之前运行过__construct
?
在nginx/error.log
我看到以下错误:</p>
74988#0:*380 kevent() 在从上游读取响应标头时报告关闭连接(54:对等方重置连接),客户端:127.0.0.1,服务器:local.grpc.develop,请求:“GET / HTTP/ 1.1”,上游:“fastcgi://127.0.0.1:9000”,主机:“local.grpc.develop”
我[1] 37548 segmentation fault
在cli中运行时得到了。
解决方案
parent::__construct($data);
这应该在构造中的代码之上,以便应用程序父构造具有优先级。那么你的调试应该会更容易。当您在父构造之前退出时,您会杀死应用程序。
推荐阅读
- hive - Hive 解释计划在哪里查看全表扫描?
- windows-console - python 控制台上的“选择”一词代表什么?
- c++ - C ++无法在列表迭代后使用插入附加值
- azure - 在公司代理网络中的 WebAPI 中运行时 ADAL [AquireTokenAsync] 超时
- rust - 在 Substrate 运行时 crate 中定义的 Log 类型在哪里?
- java - 在输出中输入特定日期时,我收到“null”
- nuget - 我可以使用不在 .NET Framework 上的旧版 dll 创建 NuGet 包(或其他包)吗?
- go - 有没有一种优雅的方式以快速失败的方式并行运行带有嵌套包的 Go 模块测试?
- mysql - 将具有自定义架构的 mysql 用户存储添加到 WSO2 身份服务器
- javascript - 无法更改 Vue 组件的对象属性(真正的异常)