I once tried to go over these once a day - that proved to be too much so I'm going to start doing these on Wednesdays or Thursdays. To keep things varied I wrote a script for this.

Code php:
<?php
header("Content-Type: text/plain");
 
$f = get_defined_functions();
$f = $f['internal'];
 
shuffle($f);
 
echo array_pop($f);
 
exit;

What I'm going to do is each Wednesday I'll run this script and write something about the function it spits out at me. So, in a nod to the old Animaniacs cartoon let us begin...


Array of PHP functions, shuffle and pop -
Tell us the which function we'll learn this stop.


parse_ini_file


Cool, ok. This function parses ini files in a format similar to the php.ini file itself, but as of PHP 5.3 a newer version of the ini file format is supported that allows some degree of nesting. INI files are a great way of storing configuration data for your program, and I've personally used them extensively for that purpose. While it is true that YAML and XML files allow for more data depth and complexity than INI files, INI files have a strong advantage in being much faster to parse and, in my opinion, any data amount so extensive that a YAML or XML file would be required should probably reside in your database.

Parsing ini files is one of the very first things my own framework does, as seen here in this function from its core bootstrap class.

Code php:
	/**
	 * Load and parse the config.ini file of this project.
	 * @param $config
	 * @param $path
	 */
	private final static function loadConfig( $config ) {
 
		self::$config = parse_ini_file($_SERVER['PNL_ROOT'].'core/config/core.ini', true);
 
		if ( self::$config == false ) {
			die('Parse error in configuration file. PNL cannot start.');
		}
 
		if (!is_null($config)) {
			$childConfig = parse_ini_file( $config, true );
 
			if ( $childConfig == false ) {
				die('Parse error in supplied override configuration file. PNL cannot start.');
			}
 
			self::$config = array_merge_recursive( self::$config, $childConfig );
		}
	}

As to what this function is doing - the framework has a master default INI file whose location relative to the root is known. The value of $_SERVER['PNL_ROOT'] is set in the httpd.conf or .htaccess file in this manner.

Code:
SetEnv PNL_ROOT "c:/xampp/pnl/"
You can actually arbitrarily load any value into the $_SERVER array from your htaccess file, though these keys should be kept minimal: The path to the framework root where its files lie, and whether to start in debug mode, are the only ones I set. That gets us to the config file, which holds the values that must be known to the system before it tries to start a database. All other data goes in the database.

PNL is designed to let one core code block serve a whole server regardless of how many vhosts it might have and clients with those hosts. Hence, the startup of the framework takes a path argument for a local config file. The function above loads that second and then uses array_merge_recursive to marry the two files together into a master config.

So, what else is there to say or questions to ask regarding this function?