UPDATE:
I'm trying to understand something about object-oriented PHP.
Let's say that I define my variable at the very top of my code with other arrays and functions (modifiers) like that:
class Shipments {
public $clean_key = [];
}
I'm trying to push an array inside my public array in this way:
class Shipments {
public function __construct($settings = array())
{
$use_access_key = $this->access_key();
$this->ee = ee();
$this->settings = $settings;
$sql = ee()->db->select('*')->from('exp_extensions')->where('class', __CLASS__)->get();
foreach ($sql->result() as $row) {
array_push($this->clean_key, unserialize($row->settings));
}
}
Then I call it in another function in this way:
public function access_key()
{
echo "<pre>";
var_dump($this->clean_key);
die();
if (isset($clean_key['mode']) && $clean_key['mode'] == "0") {
if (isset($clean_key['access_key_test'])) {
$this->access_key = array($clean_key['access_key_test']);
}
} elseif (isset($clean_key['mode']) && $clean_key['mode'] == "1") {
if (isset($clean_key['access_key_production'])) {
$this->access_key = array($clean_key['access_key_production']);
}
}
My array looks like that:
array(2) {
[0]=>
array(27) {
["access_key_test"]=>
string(22) "blabla11"
["access_key_production"]=>
string(0) ""
["mode"]=>
string(1) "0"
["ExpeditedParcel"]=>
string(1) "1"
["ExpeditedParceldrop"]=>
}
If I dump my array right after my code I obtain what I'm looking for. The problem is that, if I try to access the array from any other instance for some reason, I can't have access to my public array for example:
public function access_key()
{
var_dump($this->clean_key);
die();
}
It Wil return an Undefined variable: clean_key.
I don't understand why. The variable should be global (the array in this case) plus I'm using a __construct so I supposed to have access to the function everywhere in my code.
UPDATE: $clean_key returns null and $this->clean_key returns an arry like that:
array(0) {
}