Override core/input CI3 |
Hello folks,
All was well until I tried to upgrade to CI 3. This is the error I am getting, and don't really know why? Code: A PHP Error was encountered This is all I have on MY_Input.php Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); This is a system file: Filename: core/Common.php Line Number: 238 Code: function &get_config(Array $replace = array()) **// LINE 238** Why is it telling me it's not an array since it worked perfectly with previous versions? Thank you :
I have this file in application/core/MY_Input.php
On previous versions the function had only one parameter. After upgrading to CI 3, it started throwing an error Severity: Runtime Notice Message: Declaration of MY_Input::_clean_input_keys() should be compatible with CI_Input::_clean_input_keys($str, $fatal = true) Filename: core/MY_Input.php So I added a param $fatal = true and the error was gone. Now I have two different error: Severity: 4096 Message: Argument 1 passed to get_config() must be of the type array, string given, called in application/core/MY_Input.php on line 7 and defined. // Line 7 is $config = &get_config('config'); Filename: core/Common.php Line Number: 238 Severity: Warning Message: Invalid argument supplied for foreach() Filename: core/Common.php Line Number: 274 PHP Code: ]<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); I just can't figure out where the issue is?? It worked fine on CI 2.2.1 why not on CI 3? Thanks
It's because you're using the function improperly. It accepts an array of key => value pairs to replace in the returned config array, not a string.
because v2.2.1's method signature looks like this:
PHP Code: function &get_config($replace = array()) The word 'Array' before $replace in the v3 code enforces the type of the argument, so you get an error immediately for passing the wrong type of data to the method. In v2, the type of the argument wasn't checked, so, if you were lucky, you wouldn't get an error. Otherwise, you would get an error on line 260: PHP Code: foreach ($replace as $key => $val) The closest thing to a type check in the v2 code for this method was the following check before the foreach() mentioned above: PHP Code: if (count($replace) > 0) It really is pretty much luck that an error wasn't encountered, since the documentation of the count() function includes this in the documentation of the return value: Quote:If the parameter is not an array or not an object with implemented Countable interface, 1 will be returned. (02-16-2015, 01:54 AM)Narf Wrote: It's because you're using the function improperly. It accepts an array of key => value pairs to replace in the returned config array, not a string. How could I match the param for that function? CI 2.2.1 Code: function &get_config($replace = array()) CI 3.0.0 PHP Code: function &get_config(Array $replace = array())
Change this:
PHP Code: $config = &get_config('config'); to this: PHP Code: $config = &get_config(); 'config' was not a valid value for that argument, so it should behave the same way it did in v2.x if you don't pass anything. |
Welcome Guest, Not a member yet? Register Sign In |