PHP 未定义变量 $this

use*_*256 0 php

我在 PHP 中得到了以下代码:

class NewsletterDB {
private $connection;
public $last_query;
private $magic_quotes_active;
private $real_escape_string_exists;

function __construct() {
    $this->open_connection();
    $this->magic_quotes_active = get_magic_quotes_gpc();
    $this->real_escape_string_exists = function_exists("mysql_real_escape_string");
    $this->$connection = "";
}

public function open_connection() {
    if (!isset($this->$connection)) die("error");
    $this->$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS);
    ...
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

注意:未定义的变量:连接在/Users/...

这是为什么?我已经在 class NewsletterDB {... 后的顶部定义了变量

Sho*_*hoe 6

$this->connection不是$this->$connection。后者的意思是:获取局部变量中包含的字符串$connection并调用具有该名称的成员变量。