Salve a tutti. Sto approfondendo lo studio sui traits ma mi son ritrovato in un vicolo cieco.
Ho tre file
test.php
Codice PHP:
<?php
include_once 'traits.php';
class testclass {
use myApplication;
function __construct(){
echo $this->getConfig("name"); //Non genera errore
echo $this->getConfig("version"); //Genera errore
}
}
$test = new testclass();
?>
traits.php
Codice PHP:
<?php
trait myApplication{
private $path = "";
private $configFile = "Config.php";
public function getConfig($value){
if (!file_exists($this->path.$this->configFile)) {
trigger_error("ERROR");
} else {
@include_once $this->path.$this->configFile;
return $Config[$value];
}
}
}
Config.php
Codice PHP:
$Config['name'] = "Name";
$Config['version'] = "1.0.0";
Come potete vedere nel construct di testclass riesco ad usare la funzione solo una volta.
Non capisco il perche ma dichiamando più getConfig mi genera errore.
codice:
Notice: Undefined variable: Config
Non importa quale sia il parametro, ma se la richiamo più volte, mi genera errore.
P.S Ovviamente i file sono tutti nella stessa cartella.