Function

i am following a tutorial for a log in script, but what i don’t understand is ow the array from the $config was passed to the $path. please pardon me if its like a novice questions , i have read about functions over again , but still did not get it.can anyone help

<?php
class Config {
	public static function get($path = null) {
		if($path) {
			$config = $GLOBALS['config'];
			$path = explode('/', $path);

			foreach($path as $bit) {
				if(isset($config[$bit])) {
					$config = $config[$bit];
				}
			}

			return $config;
		}

		return false;
	}
}

http://www.php.net/manual/en/reserved.variables.globals.php

$GLOBALS is accessible anywhere, there is no scope. So inside the function, $config is set to $GLOBALS[‘config’]. Whether config was defined or not, I’m not sure.

Are you passing an argument when calling the get function?

umm your code has two flaws you probably want to know of at this stage, since if you develop a habit of coding in this way you will be in serious trouble in future. First of all, global variables a bad bad practices, and superglobal arrays should be handled much more carefully. I do not recommend messing with the $GLOBALS array, it brings more trouble than its worth. Also, static methods are poor OOP practices, you should try to avoid that too.

Config was defined in another file



$GLOBALS['config'] =array( 	'mysql' => array( 		'host' 		=> ' ', 		'username' 	=> ' ', 		'password' 	=> ' ', 		'db' 		=> ' ' 	),

The path i would have like to understand is


$path*=*explode('/',*$path);**

I was wondering when the array in the global was assigned to $path ?

I am replying from a tablet, so some typing might not come out well

@ hall of farmer ,i just started learning oop, pardon my practice i was following a tutorial will check that out too.thanks