Message: Creating default object from empty value |
[eluser]Mainboard[/eluser]
hello everyone, i have a little warning and i not understand very well how to fix that, i set this variable Code: public $settings; Code: public function set_session_data() { Severity Warning Message: Creating default object from empty value So i undertand that the reason for this is maybe because the version of PHP had a E_STRICT error reporting constant. The PHP manual states "Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.". Thus it's recommendable to enable strict PHP errors. So i want if it could to fix this in the code to get more clear code
[eluser]PhilTem[/eluser]
As long as you won't initialize all your setting keys in the class header like you did for public $settings; you will always get that error (since your PHP interpreter actually doesn't know the variables you are accessing in your foreach-loop exist. If you want to life without these PHP-errors, you can either specify all keys in the class header with something like Code: public $setting_key_1; which will only be good if you have little to no keys and if they don't change or might not be extended over time. On the other hand, you could just use an array Code: private $_items = array(); in your header which will keep all your setting items. However, you will then have to access each item with Code: $this->_config['settings_key_1'] which can be exhausting over time. Yet, there is a way to change this and still let you use $this->settings_key_1. To not write all the code for you (since I don't know if it will suit your needs) I will just give you three keywords and an URL: Magic Getter and Setter
[eluser]CroNiX[/eluser]
Why would you loop over the array only to assign each value to a property, which is another array? Just assign the array to the property. Code: $this->settings = $this->db->get('mcb_data')->result(); Code: echo $this->settings->some_key;
[eluser]Unknown[/eluser]
You're seems to be using the "myBaseClient" open source utility, in that case I've solved that issue initializing the public property called setting inside the constructor, there hasn't been any in this case so I've created one to achieve this. Code: function __construct() after that, everything went fine!. greetings. :-) |
Welcome Guest, Not a member yet? Register Sign In |