phpfuelphp

How to turn arrays to classes like fullphp


I'am using the fullPHP Library and I do not understand some sources.

The library has a config-class witch will be called like

Config::load('test.php', true);  

the test.php looks like this:

<?php

return array(
  'base_url'  => null,
  'profiling_paths' => array(
      'APPPATH' => 'APPPATH',
      'COREPATH' => 'COREPATH',
      'PKGPATH' => 'PKGPATH'
  )
);

In the class itself the test.php is interpreted like an array not like a string. How does it works?

You will find the class here: https://github.com/fuel/core/blob/1.9/develop/classes/config.php


Solution

  • In short: the Config::load('test.php', true) method call loads the content of the test.php file (array) and stores it in the Config class static::$items property array. When you call Config::get('key') the value recieves from that static::$items property array by 'key' (static::$items['key']) and returns by the method.

    If you want just to use arrays in the "object-oriented style", you can use the ArrayIterator class from the SPL library.

    $arrayObject = new ArrayIterator([]);
    

    See the official documentation.