Constants are better defined through arrays.

Post Reply
User avatar
jessica
Site Admin
Posts: 31
Joined: Thu Sep 06, 2018 3:17 pm
Location: Cincinnati, Ohio
Contact:

Constants are better defined through arrays.

Post by jessica » Wed Sep 12, 2018 6:05 am

WHAT? How? Do you even know what your talking about Jessica? Well, yes. So when creating many configurable items, you can setup NAMESPACE, and Global and pass different parameters all over the place many different ways, although one of the best methods I have used is actually pretty nice, clean and simple to implement.





$defines = array(
"DEFKEY"=>"upper", # Options are upper or lower
"VERSION"=>"0.2.1", # Define a version
"BUILD"=>"65", # and or define a build number
"ENVIRONMENT" => "DEBUG", # Assigned is Debug, QA, Production
"CLI" => false,
"N" => "\n",
"BRN" => "<br />\n",
"BR" => "<br />",
"T" => "\t",
"DS" => DIRECTORY_SEPARATOR,
"ROOT" => str_replace(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, getcwd())
);

# By assigning an array with keys you can give the ole define a quick and easy method to generate you most commonly used variables across all functions, classes, and just about anything else you throw at it.

# To define everything, now it is as simple as assigning them with a foreach loop

foreach ($defines as $key => $value) (!defined($key) ? define($key, $value) : die('Invalid constant '.$key));
Post Reply