## php – Error Undefined variable When trying to set a private variable in construct in a class

Question

this is my class:

class PagarmeDokanPagarmeFunctions{

private $api_key,$pagarme;

public function __construct(){
$this->$api_key = get_option('api_pagarme_dokan');
$this->$pagarme = new PagarMeClient($this->$api_key);
}
}


I create the private variables before the construction function, and them i add value to these vars in the construct, one of them i give the value of an option of my plugin, and the other contains another class,
but it retrieves me this warning:

Warning: Undefined variable $api_key in C:xampphtdocsshotplace_clonewp-contentpluginsintegracao-pagarme-dokanpagarme-functions.php on line 9 Warning: Undefined variable$api_key in C:xampphtdocsshotplace_clonewp-contentpluginsintegracao-pagarme-dokanpagarme-functions.php on line 10

Warning: Undefined variable \$pagarme in C:xampphtdocsshotplace_clonewp-contentpluginsintegracao-pagarme-dokanpagarme-functions.php on line 10


What am i missing?

0
12 months 2021-10-18T17:47:08-05:00 0 Answers 0 views 0