PHP变量被读取为空

PHP变量被读取为空,php,class,post,Php,Class,Post,我有一个带有函数的类,函数调用变量,由于某种原因,当它在开始设置时,它显示为空。(顺便说一下,不是完整的代码)(url用作函数变量中的路径) 它将返回如下内容: 在COSTRUCT中初始化变量: public $domain; protected $key; protected function __construct() { $this->domain = 'http://rbx-js.herokuapp.com'; $this->key

我有一个带有函数的类,函数调用变量,由于某种原因,当它在开始设置时,它显示为空。(顺便说一下,不是完整的代码)(url用作函数变量中的路径)

它将返回如下内容:

在COSTRUCT中初始化变量:

public      $domain;
protected   $key;     

protected function __construct()
{
    $this->domain = 'http://rbx-js.herokuapp.com';
    $this->key    = '';
}

protected function post($url, $data)
{
    foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    $fields_string = rtrim($fields_string,'&');

    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL,$this->domain.$url);
    curl_setopt($ch,CURLOPT_POST,count($data));
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);
    return $result;
}

顶部的变量赋值和
post
函数的缩进之间的选项卡有什么问题?哪个变量显示为空?我怀疑
$domain
属性在其他地方被覆盖,例如在类构造函数中。为什么
init()
?您需要手动调用该函数。为什么不建议使用
\uu construct()
?是的,我已经编辑了答案。我通常使用init,但我从继承的自定义基类调用它。
public      $domain;
protected   $key;     

protected function __construct()
{
    $this->domain = 'http://rbx-js.herokuapp.com';
    $this->key    = '';
}

protected function post($url, $data)
{
    foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    $fields_string = rtrim($fields_string,'&');

    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL,$this->domain.$url);
    curl_setopt($ch,CURLOPT_POST,count($data));
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);
    return $result;
}