DB query caching and php 7.2 |
Hello,
I just upgraded my server to PHP 7.2 and faced an error in the line 2673 of the file DB_query_builder.php the error is a result of the change in the behavior of the function count() in PHP 7.2 and I did wrote a fast fix for that problem. It might not be the best approach but it did the job. I changed this: PHP Code: for ($i = 0, $c = count($this->$qb_variable); $i < $c; $i++) to PHP Code: if (null!=$this->$qb_variable)
Are you sure this is wise? It seems you could royally mess up the QB caching mechanism with that change.
Also consider that the "Error" is only a warning, and as such, it does not stop script execution. count() still returns an integer value of zero as it always has when NULL is passed as an argument. In a production environment where the PHP warning should not be displayed there will be no consequences. The question I have for you is: What is the query that creates that condition? I suspect that's where the real problem is.
No, I am not sure and this partially why I posted it here. But what I thought is: if the count() return 0 then the loop will never be executed which make it safe to check for null before even try to run the loop.
Is it possible that your code is triggering this warning, and that the warning is only happening because you are doing something wrong?
I didn't consider that because the code was working perfectly with PHP 7.0, the error didn't show until I upgraded to PHP 7.2
It would be good to have you share the minimal example of how you can reproduce this problem, because I'm sure if there is a bug that Narf would acknowledge it, and probably tell you it's already taken care of in the next release.
(12-26-2017, 02:19 PM)skunkbad Wrote: Is it possible that your code is triggering this warning, and that the warning is only happening because you are doing something wrong? this is an example for a code that will produce the error with PHP 7.2 and CodeIgniter 3.1.6 PHP Code: $start = 0;
Is this a custom method? If not then it is wrong.
PHP Code: $total = $this->db->count_all_results(); It should be. PHP Code: $total = $this->db->count_all(); Try remarking that line out and see what happens. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(12-28-2017, 05:12 AM)InsiteFX Wrote: Is this a custom method? If not then it is wrong. It is here in the documentation https://codeigniter.com/user_guide/datab...ll_results (12-26-2017, 08:24 PM)skunkbad Wrote: It would be good to have you share the minimal example of how you can reproduce this problem, because I'm sure if there is a bug that Narf would acknowledge it, and probably tell you it's already taken care of in the next release. Yep: https://github.com/bcit-ci/CodeIgniter/pull/5282 |
Welcome Guest, Not a member yet? Register Sign In |