将字符串附加到关联数组
Appending string to associative array
我正在尝试将 class 的 属性 附加到存储在关联数组中的值的末尾。
public $encoded_url = urlencode(get_permalink());
public $social_buttons = array(
'facebook' => 'https://www.facebook.com/sharer.php?u='.$this->encoded_url.'',
'twitter' => '',
'google-plus' => '',
'linkedin' => '',
'pinterest' => ''
);
但是,我遇到了以下错误:
PHP Parse error: syntax error, unexpected '$this' (T_VARIABLE)
不胜感激,非常感谢:)
$this 在该上下文中不存在,您只能从函数中访问 $this。我建议在构造函数中设置该值。
我正在尝试将 class 的 属性 附加到存储在关联数组中的值的末尾。
public $encoded_url = urlencode(get_permalink());
public $social_buttons = array(
'facebook' => 'https://www.facebook.com/sharer.php?u='.$this->encoded_url.'',
'twitter' => '',
'google-plus' => '',
'linkedin' => '',
'pinterest' => ''
);
但是,我遇到了以下错误:
PHP Parse error: syntax error, unexpected '$this' (T_VARIABLE)
不胜感激,非常感谢:)
$this 在该上下文中不存在,您只能从函数中访问 $this。我建议在构造函数中设置该值。