Zen Cart Logo
Forums / General Questions / Need some help diagnosing functions_general,php errors

Need some help diagnosing functions_general,php errors

Views: 2,224

Results 1 to 20 of 29
11 Feb 2013, 20:52
#1
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Need some help diagnosing functions_general,php errors

I am getting nowhere fast posting in the contributions and addons section with regard to this mod so apologies for posting in general questions, however, I am hoping that I may get more views from the gurus out there that may be able to spot the problem.

I am using the dynamic filter sidebox addon. everything is working great apart from getting some PHP warnings in the log directory building up.

I have seen similar posts and have tried some of the suggestions, however none seem to be fixing hte pronlem that I have.

the only file that appeared to be out of date is the function_general.php when installing so I did a merge on the file which maybe thats why I am having issues..

the warning I get is:
PHP Warning: strlen() expects parameter 1 to be string, array given in /home/site/public_html/newsite/includes/functions/functions_general.php on line 158

now the code that is causing the warnings and that I merged was like this:

 function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {

    if (!is_array($exclude_array)) $exclude_array = array();
    $exclude_array = array_merge($exclude_array, array(zen_session_name(), 'main_page', 'error', 'x', 'y'));
    $get_url = '';
    if (is_array($_GET) && (sizeof($_GET) > 0)) {
      reset($_GET);
      while (list($key, $value) = each($_GET)) {
 //removed below for merging dynamic filter
 //      if (is_array($value) || in_array($key, $exclude_array)) continue;
 //      if (strlen($value) > 0) {
 //         $get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';

// bof dynamic filter 1 of 3

if ( (!in_array($key, $exclude_array)) && (strlen($value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {

// eof dynamic filter 1 of 3
          if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
//    die ('here');
            $get_url .= $key . '/' . rawurlencode(stripslashes($value)) . '/';
          } else {
// bof dynamic filter 2 of 3
            if (is_array($value)) {
              foreach($value as $arr){
                $get_url .= zen_sanitize_string($key) . '[]=' . rawurlencode(stripslashes($arr)) . '&';
              }
            } else {
// eof dynamic filter 2 of 3
              $get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';
// bof dynamic filter 3 of 3
			}
// eof dynamic filter 3 of 3
          }

        }
      }
    }
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);

    return $get_url;
  }

I found that the errors stopped if I removed one of the lines I commented out like this:

 function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {

    if (!is_array($exclude_array)) $exclude_array = array();
    $exclude_array = array_merge($exclude_array, array(zen_session_name(), 'main_page', 'error', 'x', 'y'));
    $get_url = '';
    if (is_array($_GET) && (sizeof($_GET) > 0)) {
      reset($_GET);
      while (list($key, $value) = each($_GET)) {
 //removed below for merging dynamic filter
       if (is_array($value) || in_array($key, $exclude_array)) continue;
 //      if (strlen($value) > 0) {
 //         $get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';

// bof dynamic filter 1 of 3

if ( (!in_array($key, $exclude_array)) && (strlen($value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {

// eof dynamic filter 1 of 3
          if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
//    die ('here');
            $get_url .= $key . '/' . rawurlencode(stripslashes($value)) . '/';
          } else {
// bof dynamic filter 2 of 3
            if (is_array($value)) {
              foreach($value as $arr){
                $get_url .= zen_sanitize_string($key) . '[]=' . rawurlencode(stripslashes($arr)) . '&';
              }
            } else {
// eof dynamic filter 2 of 3
              $get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';
// bof dynamic filter 3 of 3
			}
// eof dynamic filter 3 of 3
          }

        }
      }
    }
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);

    return $get_url;
  }

however, when the errors stopped, I noticed that the filter is lost when navigating to page 2 of the results (so basically breaks it)

So I guess I have two options, dig dig dig and see if there is a proper solution, or, somehow find a way to stop the error log building up by ignoring the warning some how as it doesn't seem to actually affect the functionality of the site at all. After all its only a warning right??

Can anyone please help? I spoke to a friend that also has this mod on a fresh install of zen-cart and also has the same warning log files.

Thanks in Advance,

11 Feb 2013, 21:31
#2
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Need some help diagnosing functions_general,php errors

This is from my functions_general.php file, and I don't get any errors, maybe it is helping.
it's from ZC 1.5.1

/**
 * Return all HTTP GET variables, except those passed as a parameter
 *
 * The return is a urlencoded string
 *
 * @param mixed either a single or array of parameter names to be excluded from output
*/
  function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {

    if (!is_array($exclude_array)) $exclude_array = array();
    $exclude_array = array_merge($exclude_array, array(zen_session_name(), 'main_page', 'error', 'x', 'y'));
    $get_url = '';
    if (is_array($_GET) && (sizeof($_GET) > 0)) {
      reset($_GET);
      while (list($key, $value) = each($_GET)) {
// bof dynamic filter 1 of 3
        if ( (!in_array($key, $exclude_array)) && (strlen($value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
// eof dynamic filter 1 of 3
// bof dynamic filter 2 of 3
            if (is_array($value)) {
              foreach($value as $arr){
                $get_url .= zen_sanitize_string($key) . '[]=' . rawurlencode(stripslashes($arr)) . '&';
              }
            } else {
// eof dynamic filter 2 of 3
              $get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';
// bof dynamic filter 3 of 3
      }
// eof dynamic filter 3 of 3
          
        }
      }
    }
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);

    return $get_url;
  }
11 Feb 2013, 21:36
#3
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need some help diagnosing functions_general,php errors

I just tried you code and I still get the PHP warning.. :'(

I am running CEON URI Mapping but I get the same even with the mapping switched off so pretty sure its not that.. I dont get it :(

11 Feb 2013, 21:41
#4
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need some help diagnosing functions_general,php errors

the line the warning is triggering on is this one specifically:

   if ( (!in_array($key, $exclude_array)) && (strlen($value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
11 Feb 2013, 21:58
#5
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need some help diagnosing functions_general,php errors

@Design75 so you don't get any php warning files in your /log directory at all??

11 Feb 2013, 22:13
#6
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Need some help diagnosing functions_general,php errors

no, not a single one

11 Feb 2013, 22:16
#7
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need some help diagnosing functions_general,php errors

That's really weird. This code is above me, do you know what it's all doing etc? If so any ideas where else I might look as clearly something isn't liking it even now I'm using your code for that function exactly.

Says its expecting an array, so one would assume its perhaps not seeing one when it should? Anyway we can degug it to see where it's going wrong?

11 Feb 2013, 22:30
#8
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Need some help diagnosing functions_general,php errors

I am not much of a php guru. I know enough to be dangerous :laugh:. I am learning, and I will try to help.

What version of ZC, php, and mysql are you using? maybe I can try to duplicate the error by setting up a test-site with the same variables

11 Feb 2013, 22:40
#9
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need some help diagnosing functions_general,php errors

Thanks,

Zen Cart 1.5.1
Database Patch Level: 1.5.1
PHP Version: 5.3.10
Database: MySQL 5.1.66-cll

I have various mods but only one that really has core overrides is CEON URI MAPPINGS

I guess I need to understand where some of these variables on that line are called from to see if any of the files are modified by any of the mods I had installed?

11 Feb 2013, 23:08
#10
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Need some help diagnosing functions_general,php errors

Okay, it's bedtime over here, so I'll report back tomorrow with my results from the test

11 Feb 2013, 23:24
#11
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Need some help diagnosing functions_general,php errors

I had one last idea before shutting down

// bof dynamic filter 1 of 3
        if ( (!in_array($key, $exclude_array)) && (strlen((int)$value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
// eof dynamic filter 1 of 3

I added (int) to the strlen and it seems to do the job, but I am no expert.

p.s. I wasn't getting any errors at first because I made some other stupid mistake. after fixing that the errors started coming in :blush: until I added the int

12 Feb 2013, 02:19
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Need some help diagnosing functions_general,php errors

if ( (!in_array($key, $exclude_array)) && (strlen($value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {  

The statement is testing conditions for some situation, based on $key which stands for the name of the current array-item key in the array being evaluated, and $value which holds the value of the current key.
Breaking down the statement,
if ( (!in_array($key, $exclude_array))
---> the key is not in a list of keys to exclude,

&& (strlen($value) > 0 || is_array($value) && array_filter($value) )
---> and the value is a string that is longer than '' (empty or blank) or the value is an array and this filter applied to it gives "true' or a positive result

&& ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
---> and the key is not one of these names.

Apparently $value should not be an array if the key passes the "exclude" test. Casting it to int seems to make it safe, but destroys the test's value (unless it is a string starting with a number, it will be viewed as 0 (zero)); casting it to string will keep the information if it is a string, and hopefully make it safe if it is an array.

Best would be to find out why it is being an array when it apparently should not, and fixing that, or testing for it being an array and handling it appropriately if it is.

12 Feb 2013, 02:31
#13
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Need some help diagnosing functions_general,php errors

&& (strlen($value) > 0 || is_array($value) && array_filter($value) ) 

could be rewritten as

&& (is_string($value) && strlen($value) > 0 || is_array($value) && array_filter($value) ) 
12 Feb 2013, 07:39
#15
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need some help diagnosing functions_general,php errors

Thanks very much. Speak soon :-)

12 Feb 2013, 07:50
#16
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need some help diagnosing functions_general,php errors

Wow loads of ideas, just replied to what I thought was te last post then boom all of a sudden I had all these great suggestions.
Now @Design75 did your fix work? Does it work when applying a filter and then going to the second page of te filter results

@gjh42 I will try your suggestion also thanks for your input, and thank you for explaining the code :-)

@DrByte how can I incorporate that fix with the dynamic filter code?

Thanks all

12 Feb 2013, 08:16
#17
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Need some help diagnosing functions_general,php errors

philip937:

Wow loads of ideas, just replied to what I thought was te last post then boom all of a sudden I had all these great suggestions.
Now @Design75 did your fix work? Does it work when applying a filter and then going to the second page of te filter results

@gjh42 I will try your suggestion also thanks for your input, and thank you for explaining the code :-)

@DrByte how can I incorporate that fix with the dynamic filter code?

Thanks all

Wow indeed ;)

@philip937: My fix worked, but gjh42 is better. Like he said, my fix always assumes an integer, which may not be the case.

@gjh42 :thumbsup: thank you for the lesson:smartalec:, like said before. I am learning PHP bit by bit. Everyday I am understanding a little more.

@DrByte, I am using the functions_general.php that came with ZC 1.5.1, and merged the dynamic filter code in to it.

This is how the merged result looks like, including Glenn's fix.

  function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {

    if (!is_array($exclude_array)) $exclude_array = array();
    $exclude_array = array_merge($exclude_array, array(zen_session_name(), 'main_page', 'error', 'x', 'y'));
    $get_url = '';
    if (is_array($_GET) && (sizeof($_GET) > 0)) {
      reset($_GET);
      while (list($key, $value) = each($_GET)) {
// bof dynamic filter 1 of 3
        if ( (!in_array($key, $exclude_array)) && (is_string($value) && strlen($value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
// eof dynamic filter 1 of 3
// bof dynamic filter 2 of 3
            if (is_array($value)) {
              foreach($value as $arr){
                $get_url .= zen_sanitize_string($key) . '[]=' . rawurlencode(stripslashes($arr)) . '&';
              }
            } else {
// eof dynamic filter 2 of 3
              $get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';
// bof dynamic filter 3 of 3
      }
// eof dynamic filter 3 of 3
          
        }
      }
    }
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);

    return $get_url;
  }
12 Feb 2013, 08:51
#18
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need some help diagnosing functions_general,php errors

Thanks guys, just got to work so will have to test later this evening on my set up.

Many many many thanks :)

12 Feb 2013, 18:32
#19
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need some help diagnosing functions_general,php errors

Design75:

Wow indeed ;)

@philip937: My fix worked, but gjh42 is better. Like he said, my fix always assumes an integer, which may not be the case.

@gjh42 :thumbsup: thank you for the lesson:smartalec:, like said before. I am learning PHP bit by bit. Everyday I am understanding a little more.

@DrByte, I am using the functions_general.php that came with ZC 1.5.1, and merged the dynamic filter code in to it.

This is how the merged result looks like, including Glenn's fix.

function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {

if (!is_array($exclude_array)) $exclude_array = array();
$exclude_array = array_merge($exclude_array, array(zen_session_name(), 'main_page', 'error', 'x', 'y'));
$get_url = '';
if (is_array($_GET) && (sizeof($_GET) > 0)) {
  reset($_GET);
  while (list($key, $value) = each($_GET)) {

// bof dynamic filter 1 of 3
if ( (!in_array($key, $exclude_array)) && (is_string($value) && strlen($value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
// eof dynamic filter 1 of 3
// bof dynamic filter 2 of 3
if (is_array($value)) {
foreach($value as $arr){
$get_url .= zen_sanitize_string($key) . '[]=' . rawurlencode(stripslashes($arr)) . '&';
}
} else {
// eof dynamic filter 2 of 3
$get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';
// bof dynamic filter 3 of 3
}
// eof dynamic filter 3 of 3

    }
  }
}
while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);

return $get_url;

}


LOVE YOU ALL!!!! SORTED. :hug:
12 Feb 2013, 19:12
#20
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Need some help diagnosing functions_general,php errors

gjh42:

&& ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
---> and the key is not one of these names.
... and that part is fully redundant because the test for $exclude_array already handles those names.