Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2011
    Location
    Espoo, Finland
    Posts
    49
    Plugin Contributions
    0

    Default "Undefined variable" warning in zen_build_keyword_where_clause function

    Happy New Year everyone

    PHP 8 can generate "Undefined variable" and "Passing null to parameter" warnings in zen_build_keyword_where_clause function (functions_strings.php, line 211)

    Code:
        function zen_build_keyword_where_clause($fields, $string, $startWithWhere = false)
       {
            global $db, $zco_notifier;
    
            $zco_notifier->notify('NOTIFY_BUILD_KEYWORD_SEARCH', '', $fields, $string);
            if (zen_parse_search_string(stripslashes($string), $search_keywords)) {
                $where_str = " AND (";
     
                ...
    
            }
            if (substr($where_str, -7) === '( ()  )') {
                return ' ';
            }
            return $where_str ?? ' ';
        }
    My quick suggestion:

    Code:
    if (!empty($where_str) AND substr($where_str, -7) === '( ()  )') {
                return ' ';
            }
    Last edited by yesaul; 5 Jan 2024 at 05:25 PM.

  2. #2
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: "Undefined variable" warning in zen_build_keyword_where_clause function

    There's a number of ways to potentially address:
    1. Pre-assign a default value, then change the final torn to just send the value of $where_str.
    2. Add a test for emptiness or lack of setting before checking if made of empty parentheses. The return of this test to be whatever default or representation of being empty. Then remove the test against being set to just return the $where_str value.
    3. Put the test of the empty parentheses inside the if statement that appears to generate that result. And apply variations of the above.

    But, the solution adopted is/was in this pull request: https://github.com/zencart/zencart/pull/5747/files
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. Replies: 32
    Last Post: 6 Sep 2020, 09:03 PM
  2. Replies: 27
    Last Post: 20 Nov 2012, 04:04 AM
  3. Help me please!!"Warning: Variable passed to each() is not an array or object"
    By delequah in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 11 Aug 2007, 11:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR