• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DB query caching and php 7.2

#1
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++)
 
           {
 
               if ( ! in_array($this->{$qb_variable}[$i], $qb_newTRUE))
 
               {
 
                   $qb_new[] = $this->{$qb_variable}[$i];
 
                   if ($val === 'select')
 
                   {
 
                       $qb_no_escape[] = $this->qb_no_escape[$i];
 
                   }
 
               }
 
           


to

PHP Code:
if (null!=$this->$qb_variable)
{
    for (
$i 0$c count($this->$qb_variable); $i $c$i++)
    {
        if ( ! 
in_array($this->{$qb_variable}[$i], $qb_newTRUE))
        {
            
$qb_new[] = $this->{$qb_variable}[$i];
            if (
$val === 'select')
            {
                
$qb_no_escape[] = $this->qb_no_escape[$i];
            }
        }
    }

Reply

#2
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.
Reply

#3
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.
Reply

#4
Is it possible that your code is triggering this warning, and that the warning is only happening because you are doing something wrong?
Reply

#5
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
Reply

#6
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.
Reply

#7
(12-26-2017, 03: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;
        $this->db->start_cache();
        $this->db->select('ID, Title, Name, address.city as City, address.state as state')
                 ->from('customers')
                 ->join('address''customers.ID = address.CusID')
                 ->order_by('ID''ASC');
        $this->db->stop_cache();
        $total $this->db->count_all_results();
        $ents $this->db->limit(25$start)
                         ->get()
                         ->result_array();
        $this->db->flush_cache(); 
Reply

#8
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 )
Reply

#9
(12-28-2017, 06:12 AM)InsiteFX Wrote: 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.

It is here in the documentation

https://codeigniter.com/user_guide/datab...ll_results
Reply

#10
(12-26-2017, 09: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
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.