View Single Post
  #8  
Old 02-28-2019, 12:19 AM
 
aim aim is offline
Advanced Staff Users
 

X-Cart team
  
Join Date: Dec 2008
Posts: 928
 

Default Re: PHP 5.6 and 7.0 Discontinued: How It Affects Your X-Cart 4 Store

Quote:
Originally Posted by cflsystems
Keep in mind the patches are not complete and do not fully address all issues older XC versions will have with PHP 7.2+

One example is the use of each() - this has been removed in XC 4.7.9 and later but every version before that has it. And the patches do not address this.

each() has been deprecated since PHP 7.2 and most likely will be removed with 7.4 or whatever version they decide on. Cart still works but logs will be full of warnings and XC 4.7.9+ and the patches are not consistent in what they fix.

As PHP puts it: This function has been DEPRECATED as of PHP 7.2.0. Relying on this function is highly discouraged.

There are other warnings and notices as well that will show after the patches but not with newest XC4 version.

So to me the patches are incomplete.

And while looking at this (the below code is from 4.7.10) it just doesn't make sense

PHP Code:
if (
        empty(
$product['meta_description'])
        || empty(
$product['meta_keywords'])
    ) {

        
$ids array_reverse(func_get_category_path($product['categoryid']));

        
$parents func_query_hash("SELECT categoryid, meta_description, meta_keywords FROM $sql_tbl[categories] WHERE categoryid IN ('".implode("', '"$ids)."') AND override_child_meta = 'Y'""categoryid"false);

        foreach (
$ids as $cid) {
            if (
                !empty(
$product['meta_description'])
                && !empty(
$product['meta_keywords'])
            ) {
                break;
            }
. . . . . . . . . . . 
   }


The "if" will run if meta_description OR keta_meywords are empty but then the following "foreach" breaks only if meta_description AND meta_keywords are not empty?!
The code will never get to the "foreach" if both are not empty in the first place....
The second "if" is absolutely unnecessary.

Hello,

Thank you for the notes.

The code above works as the http://php.net/manual/en/control-structures.do.while.php construction
i.e. the first iteration runs anyway. It is a replacement for the deprecated PHP each call

Code:
@@ -565,7 +569,14 @@ function func_get_category_meta($categoryid, $category = null) array_shift($ids); $parents = func_query_hash("SELECT categoryid, meta_description, meta_keywords FROM $sql_tbl[categories] WHERE categoryid IN ('".implode("', '", $ids)."') AND override_child_meta = 'Y'", "categoryid", false); - while ((list(,$cid) = each($ids)) && (empty($category['meta_description']) || empty($category['meta_keywords']))) { + foreach ($ids as $cid) { + if ( + !empty($category['meta_description']) + && !empty($category['meta_keywords']) + ) { + break; + } + $parents[$cid]['meta_description'] = trim($parents[$cid]['meta_description']); $parents[$cid]['meta_keywords'] = trim($parents[$cid]['meta_keywords']);


The whole code looks like

PHP Code:
if (empty($category['meta_description']) || empty($category['meta_keywords'])) {

        
$ids array_reverse(func_get_category_path($categoryid));

        
array_shift($ids);
        
$parents func_query_hash("SELECT categoryid, meta_description, meta_keywords FROM $sql_tbl[categories] WHERE categoryid IN ('".implode("', '"$ids)."') AND override_child_meta = 'Y'""categoryid"false);

        foreach (
$ids as $cid) {
            if (
                !empty(
$category['meta_description'])
                && !empty(
$category['meta_keywords'])
            ) {
                break;
            }

            
$parents[$cid]['meta_description'] = trim($parents[$cid]['meta_description']);
            
$parents[$cid]['meta_keywords'] = trim($parents[$cid]['meta_keywords']);

            if (empty(
$category['meta_description']) && !empty($parents[$cid]['meta_description']))
                
$category['meta_description'] = $parents[$cid]['meta_description'];

            if (empty(
$category['meta_keywords']) && !empty($parents[$cid]['meta_keywords']))
                
$category['meta_keywords'] = $parents[$cid]['meta_keywords'];
        }
    } 

The foreach tries to go through the $ids array in order to fill the empty meta_description/meta_keywords of the category from the filled fields of its parents.

As for the deprecated warnings, I tried to make minimal patches so as to achieve the maximal compatibility with the client's code.

Thank you.
__________________
Sincerely yours,
Ildar Amankulov
Head of Maintenance group
Reply With Quote