laravel sizeof():参数必须是一个数组或者一个实现了Countable的对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49506003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:34:08  来源:igfitidea点击:

sizeof(): Parameter must be an array or an object that implements Countable

phphtmllaravellaravel-5paypal

提问by Ulai Nava

help me please

请帮帮我

geting error sizeof(): Parameter must be an array or an object that implements Countable

得到错误 sizeof(): 参数必须是一个数组或一个实现 Countable 的对象

ErrorException {#654 ▼
  #message: "sizeof(): Parameter must be an array or an object that implements Countable"
  #code: 0
  #file: "C:\Primer_Proyecto\Ventas\vendor\paypal\rest-api-sdk-php\lib\PayPal\Common\PayPalModel.php"
  #line: 179
  #severity: E_WARNING
  trace: {▼
    C:\Primer_Proyecto\Ventas\vendor\paypal\rest-api-sdk-php\lib\PayPal\Common\PayPalModel.php:179 {?}
    Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() {}
    C:\Primer_Proyecto\Ventas\vendor\paypal\rest-api-sdk-php\lib\PayPal\Common\PayPalModel.php:179 {?}
    C:\Primer_Proyecto\Ventas\vendor\paypal\rest-api-sdk-php\lib\PayPal\Common\PayPalModel.php:281 {?}
    C:\Primer_Proyecto\Ventas\vendor\paypal\rest-api-sdk-php\lib\PayPal\Common\PayPalModel.php:296 {?}
    C:\Primer_Proyecto\Ventas\vendor\paypal\rest-api-sdk-php\lib\PayPal\Api\Payment.php:557 {?}
    C:\Primer_Proyecto\Ventas\app\paypal.php:26 {▼
      ? try{\r
      ? \t$payment->create($this->_apiContext);\r
      ? }\r
      arguments: {?}
    }

This is the paypal.php code

这是paypal.php代码



public function generate(){
    $payment = \PaypalPayment::payment()->setIntent("sale")
        ->setPayer($this->payer())
        ->setTransactions([$this->transaction()])
        ->setRedirectURLs($this->redirectURLs());

    try {
        $payment->create($this->_apiContext);
    }
    catch(\Exception $ex){
        dd($ex);
        exit(1);
    }

    return $payment;
}


public function __construct($shopping_cart){
    $this->_apiContext = \PaypalPayment::ApiContext($this->_ClientId, $this  ->_ClientSecrete);
    $config = config("paypal_payment");
    $flatConfig = array_dot($config);
    $this->_apiContext->setConfig($flatConfig);
    $this->shopping_cart = $shopping_cart;
}

I do not see the error, I have stayed too long looking for what is my mistake

我没有看到错误,我呆得太久了,一直在寻找我的错误

回答by patricus

The error is in the paypal\rest-api-sdk-phppackage you are using. The version of the package you are using is, apparently, not exactly compatible with PHP 7.2.

错误出在paypal\rest-api-sdk-php您正在使用的包中。您使用的软件包版本显然与 PHP 7.2 不完全兼容。

The specific error you are getting has been fixed in the latest version of the package (1.13.0). Update the package to the latest version, and this issue will be fixed. I cannot say what other issues may pop up, though.

您遇到的特定错误已在最新版本的软件包 ( 1.13.0) 中得到修复。将软件包更新到最新版本,此问题将得到修复。不过,我不能说可能会出现什么其他问题。

In the 1.12.0version, the specific line that is failing is:

1.12.0版本中,失败的特定行是:

} elseif (sizeof($v) <= 0 && is_array($v)) {

In PHP 7.2, if $vis not Countable, the sizeof()call will emit a warning, and Laravel will turn that warning into an exception.

在 PHP 7.2 中,如果$v不是 Countable,则sizeof()调用会发出警告,Laravel 会将警告转换为异常。

In the 1.13.0version, they updated the condition to be

1.13.0版本中,他们将条件更新为

} elseif (is_array($v) && sizeof($v) <= 0) {

Now, sizeof()will only be called when $vis an array, and therefore is guaranteed to be Countable, thus eliminating the warning.

现在,sizeof()只会在$v是数组时调用,因此保证是可数的,从而消除警告。