Global PHP App Configuration Constants & "Includes" -
i creating/re-building sizable php app/website uses few different api's , interfaces database. , so, have store api keys, app keys , other such configuration data centrally accessible of different files/pages.
currently, i'm declaring variables in global context , including them using require_once():
<?php //config.php $api_key['somename'] = "this_is_my_api_key"; $api_key['othername'] = "another_api_key"; $app_id['somename'] = "app_id_here"; $app_id['othername'] = "other_app_id"; //so on , forth, of api data need, api urls //also, i'm declaring things this... $__sitewide_killswitch = false; $__debug_mode = false; $__display_errors = false; ?> then, in other files, reference these variables this:
require_once('path/to/config.php'); only downside if have reference them in functions, since not superglobals $_globals or $_session variables, instance, have this:
function database_connect( ... ) { global $api_key, $app_id, $api_url; //etc... ... ... } i want avoiding passing in api key's in through function if can. hoping best practices on declaring site-wide global constants , maybe avoid calling global keyword @ beginning of each function.
should using const in declarations? benefit in using define() function?
am doing right thing require_once() or there better way this?
what think? how should doing this? thanks!
Comments
Post a Comment