많이 나타나는 PHP 오류 WordPress Plugins 오랫동안 업데이트되지 않았거나 최신 버전의 PHP와 호환되지 않습니다. PHP Warning: sizeof(): Parameter must be an array or an object that implements Countable.
이 시나리오에서는 모듈에서 PHP 오류가 발생했습니다. Cross Sell Product Display 우커머스용.
FastCGI sent in stderr: "PHP message: PHP Warning: sizeof(): Parameter must be an array or an object that implements Countable in /web/path/public_html/wp-content/plugins/cross-sell-product-display-for-woocommerce/templates.php on line 18
오류가 발생하는 이유 PHP Warning: sizeof(): Parameter must be an array or an object that implements Countable ?
이 PHP 오류를 생성하는 문제는 함수입니다. sizeof()
PHP 7.2 이상 버전에서 주어진 매개변수가 하나가 아닌 경우 이 오류를 생성할 수 있습니다. array 또는 인터페이스를 구현하는 객체 Countable.
따라서 PHP 버전 업데이트 후 오류가 자주 발생합니다.
에 의해 생성된 PHP 오류를 해결하는 방법 sizeof()
?
가장 간단한 방법은 함수 호출을 대체하는 것입니다. sizeof()
함수 호출로 count()
.
이전 버전의 모듈을 사용하시는 분들의 경우 Cross Sell Product Display, 해결책은 간단합니다. 18인치 라인의 기능이 대체됩니다. templates.php.
function cdxfreewoocross_get_cross_sell_products($product_id=false){
if($product_id ===false ){
if(!is_product()){return false;}
$product_id = (int)get_the_ID();
if($product_id=='0'){return false;}
}
$crosssells = get_post_meta( $product_id, '_crosssell_ids',true);
if ( sizeof($crosssells ) == 0 || $crosssells =='') { return false; }
return $crosssells;
}
그것이있는 위의 코드 sizeof() 다음으로 대체됩니다.
function cdxfreewoocross_get_cross_sell_products($product_id=false){
if($product_id ===false ){
if(!is_product()){return false;}
$product_id = (int)get_the_ID();
if($product_id=='0'){return false;}
}
$crosssells = get_post_meta( $product_id, '_crosssell_ids',true);
if ( !is_array( $crosssells ) || count( $crosssells ) == 0 || $crosssells =='') { return false; }
return $crosssells;
}
이 수정은 먼저 다음을 확인합니다. $crosssells
하는 array 기능을 사용하여 is_array()
그렇지 않으면 반환 false.
의 경우 $crosssells
하는 array, 기능이 사용됩니다 count()
요소의 수를 결정하기 위해 array. 요소 수가 XNUMX이거나 $crosssells
빈 문자열이면 false가 반환됩니다.
이 튜토리얼에 대한 설명이나 추가 사항이 있으면 의견을 남겨주세요.