三三世界-百宝箱

文章 分类 标签
130 9 247

公告

暂无站点公告

PHP7中count()函数报错count(): Parameter must be an array or an object that implements Countable

三三 2021-12-07 1540 0条评论 环境搭建 php7函数报错count函数eregi函数

首页 / 正文

**此问题一般出现于支付宝的支付回调等页面,主要问题就是页面设计的时候,使用的是php5的算法,升级为php7以后相关算法和函数有所变化,导致了相关问题的出现。
一般问题如下:**

count(): Parameter must be an array or an object that implements Countable in gateways/callback/alipay_callback.php  on line 40

这种情况,需要调整count函数,修改为strlen函数一般可以得到解决。具体操作如下:

可以在执行前判断一下:

if(is_array($arr)){  
    count($arr);  
}  

如果统计的是字符串,则可以替换为:strlen()函数。

修改:$arg = substr($arg,0,count($arg)-2);

$arg = substr($arg,0,count($arg)-2);

为:$arg = substr($arg,0,strlen($arg)-1);

$arg = substr($arg,0,strlen($arg)-1);

这里注意函数修改后,后面的数字要相应增加1 。

扩展问题阅读和解决

同步发生的问题有时候还会有ereg()函数和eregi()函数的错误。这种错误一般提示为:

Call to undefined function eregi() in modules/gateways/callback/alipay_callback.php  on line 43 

**此类问题同样是由于php7和php5的部分函数不兼容导致。在php5.3以上的版本将不再支持eregi()和ereg()函数。
ereg()函数和eregi()函数用法相同,不同之处在与ereg()区分大小写,eregi()不区分大小写。
这个情况采用类似的方法替换eregi()preg_match(),具体方法参考:**

正则函数处理

ereg('aB',$str);  //区分大小写
eregi('ab',$str); //不分大小写

分别替换为:

preg_match('/aB/',$str); //区分大小写
preg_match('/ab/i',$str); //不分大小写

如果ereg_replace(); 报错替换成preg_replace();

只此问题得到解决。

评论(0)

当前没有评论,还不快来留下第一个脚印吧


Copyright 2021 三三世界-百宝箱. All Rights Reserved.

最新评论

  • 三三

    @Doug Shume it's ok for me , you can post here.

  • refugiaguenther

    Saved as a favorite, I like your website!

  • josefa

    If some one wishes to be updated with hottest technologies after that he must be visit this site and be up to date daily.

  • Penzu

    Heello would you mind sharing which blog platform you're using? I'm planning to start my own blog in the near future but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then moost blogs and I'm looking for something completely unique. P.S Apologies forr being off-topic butt I had to ask!

  • Yupoo Fendi

    Thanks to my father who shared with me regarding this webpage, this website is genuinely amazing.

  • Doug Shume

    Hi, I have an overflow of customers that I'd like to send to you but I want to make sure you can handle more leads, let me know if you'd like me to send you more info.

  • SuperWind

    zh.us.to 有效
    kms.03k.org 有效
    kms.chinancce.com
    kms.shuax.com 有效
    kms.dwhd.org 有效
    kms.luody.info 有效
    kms.digiboy.ir 有效
    kms.lotro.cc 有效
    www.zgbs.cc 有效
    cy2617.jios.org 有效

  • 三三

    @         权限问题,试试sudo 再加命令。

  •         

    你好提示Permission denied 怎么办啊

日历

2024年05月

   1234
567891011
12131415161718
19202122232425
262728293031 

文章目录

上一张 下一张