class - How can I access the contents of this PHP array? -


The files below are in PHP, I am trying to include a file that has an array in my class And then access the array. If I run print_r () on it, I get results, but if I try to access the array individually, then I do not get anything, can anyone help me?

  & lt ;? Php // config.class.php/ * example $ config = config :: getInstance (PATH_TO_CONFIG_FILE, FILE_TYPE); Echo $ config- & gt; Url; Echo $ config- & gt; exam; Echo $ config- & gt; Ip; * / Class configuration {private constant $ example = zero; Private $ option = array (); / ** * Retrieves PHP ARA file, JSON file, or IIi file and creates ARM * Full URL * @ PRAM $ filepath for the file path where the file is located, @ PRM $ is the type of file "ARRAY" JSON "" INI "* / Private Function __Composition ($ filepath, $ type = 'ARRAY') can be {switch ($ type) {case 'ARRAY': $ this- & gt; Option = $ filepath; break; Case 'INI': $ this-> Option = parse_ini_file ($ filepath, true); break; Case 'JSON': $ this- & gt; Option = json_decode (file_get_contents ($ filepath), true); break; }} Private function __clone () {} public function getInstance ($ filepath, $ type = 'ARRAY') {if (null === self: $ example) {self: $ instance = new self ($ filepath, $ type = 'ARRAY'); } Return Self: $ example; } / ** * Retrieve the price with a high priority constant * @ key to get the $ key * / public function __get ($ key) {if (isset ($ this-> option [$ key] )) {Return $ $-> Option [$ key]; }} / ** * Set a new one or update the key / value pair * @ to set the absolute $ key * * to set the value of the * absolute $ value * / public function __set ($ key, $ value) {$ This- & gt; Option [$ of] = $ value; }}? & Gt;  

And here is the config_array.ini.php file ...

   http://www.foo Return to '.com', 'db' = @ Description Array Array ('host' = & gt; 'foo.com', 'port' => 3306), 'caching' => Enabled '= & gt; wrong)); ? & Gt;  

What I'm trying to do here ...

  & lt ;? PHP $ config = config :: getInstance ('config_array.inc.php', 'RRA'); // It does not show anything $ config- & gt; Ip; // This works print_r ($ config); ? & Gt;  

You have the code working fine for me.
Check your PHP version, it is supported after __get v5.2.0

  copy $ config- & gt; Ip; // display is ok 127.0.0.1  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -