Pr0t0n Posted March 9, 2014 Share Posted March 9, 2014 Hi I got a small issue so I wont have to post all code, but as soon as I use the 2 lines below INSIDE a class I get a fatal syntax error. $_config = _BASE_DIR . "config_odin.ini"; $_parse = parse_ini_file($_config, true); He seems to say that between _BASE_DIR and "config_odin.ini"; the problem lays so must be that "."(dot). Also since php has theire own function to implement config files with ease, I dont see alot of people using it, even some serious guys just use a php file with theire own function to roll out the values. I would like to know anyones opinion about configuration files, which do you choose and why? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 9, 2014 Share Posted March 9, 2014 the error message and a few lines of code leading up to the line with the error would help. the reason .ini (and .xml) files don't get used for configuration settings in applications that are meant for others to use is, without specific security in place that prevents access to those files, anyone discovering them (or learning of their existence because they are used in a open-souce/published script) can simply request them through the browser and see all the settings they contain. the content of .php files, on the other hand, are automatically secure as the php code in them cannot be seen when or if they are browsed to. it would take breaking php on the server to be able to request a .php file and see the contents in it. Quote Link to comment Share on other sites More sharing options...
Pr0t0n Posted March 9, 2014 Author Share Posted March 9, 2014 (edited) the error message and a few lines of code leading up to the line with the error would help. the reason .ini (and .xml) files don't get used for configuration settings in applications that are meant for others to use is, without specific security in place that prevents access to those files, anyone discovering them (or learning of their existence because they are used in a open-souce/published script) can simply request them through the browser and see all the settings they contain. the content of .php files, on the other hand, are automatically secure as the php code in them cannot be seen when or if they are browsed to. it would take breaking php on the server to be able to request a .php file and see the contents in it. True but it doesnt take alot of lines of code to ensure the proper file permissions which I was aware of, but if that's a reason to not use it I dont see why not use it hehe. For the lines of code perceeding the error: class DB { private $_parse; private static $_instance = null; private $_config = _BASE_DIR . "config_odin.ini"; private $_parse = parse_ini_file($_config, true); private $_pdo; // Instance for re-use private $_query; // Last executed query; private $_error = false; private $_results; // Output; private $_count= 0; private function __construct() { try { $this->_pdo = new PDO('mysql:host='.Config::get('mysql/host').';dbname='.Config::get('mysql/db'), Config::get('mysql/user'), Config::get('mysql/passw')); echo 'Verbonden met: '.$_parse['host']; } catch (PDOException $e) { die($e->getMessage()); } } public static function getInstance() { if(!isset(self::$_instance)) { self::$_instance = new DB(); } return self::$_instance; } public function insert($table,$values = array()) { $_query = 'INSERT INTO `'.$table.'` (`'; foreach($values as $key => $value) { return $_query .= $key.', '; } $_query .= ') VALUES('; foreach($values as $key => $value) { return $_query .= $value.', '; } $_query .= '`)'; } } Well as the code is not yet complete here is everything I got at this moment. at the top you will see the two lines I mentioned. Please forget the Config::get(); its a way of using a php file as config file, which I want to remove as its not my own code. Edited March 9, 2014 by Pr0t0n Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted March 9, 2014 Solution Share Posted March 9, 2014 the line in question is a property declaration. you cannot use any php 'operators' or functions in a declaration as the definition must be completely defined at the time the code is parsed (operators/functions are evaluated at runtime.) from the php.net documentation - // invalid property declarations: public $var1 = 'hello ' . 'world'; public $var2 = <<<EOD hello world EOD; public $var3 = 1+2; public $var4 = self::myStaticMethod(); public $var5 = $myVar; the values you are trying to assign to your $_config and $_parse properties would need to be done using php code in the constructor. Quote Link to comment Share on other sites More sharing options...
Pr0t0n Posted March 9, 2014 Author Share Posted March 9, 2014 Aaah like that, got it working like a charm now. but mac_gyver if I may ask which way of configuration files you use or would use in your php app? Still trying to figure out the best way or atleast a good way to work with configuration files. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 9, 2014 Share Posted March 9, 2014 (edited) for something simple, that requires no more than a few settings, use a php array in a .php file. provide an installation script that builds the .php file or instruct the user to edit the file to set the settings. simply including the file and use the array entries. for something with more settings, where you would provide an interface to allow editing the many settings, store the configuration in a database table (you will still need a minimal .php config file to hold the database credentials.) Edited March 9, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.